Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp14233rdh; Wed, 25 Oct 2023 14:34:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7ka7mK08EWNizJghSZPTSnBWCKyqRC1A4VU5wGVS/DP+pF8qtQv2hNI+OIKyKdwqZrALf X-Received: by 2002:a05:6870:a10e:b0:1ea:6a81:8c8a with SMTP id m14-20020a056870a10e00b001ea6a818c8amr19138133oae.29.1698269677167; Wed, 25 Oct 2023 14:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698269677; cv=none; d=google.com; s=arc-20160816; b=NrIvI6JBl1SB7OQCZjfBjLG+LSy5XoOuitxf0Cmmt/PWpAA7or57caczqAZbTZyzIW 7QE7AIN86F/MjZBmhRNWhH6zdr2oMk16zA/YU+B72AA5Ql1BiCcbwfmG8EDW+obT6Ol7 KgAA9n1bU8Nlu/VSAu4ll6LG04kJkBP9/jdR+7HQse9Y4+hqPrDnhMRoJTj0dnk6ziOj 0LiAW0TI3JvhkkHhPdsMX0jbxzKKxu5TvBXCR9TlgZ+mjDVXbEgAyQfkVAImwbI9agHY iUPDRe4ZxQhItR8RdeQz+cl1Uomdt/2NhodJR8aA/eAZqTSVKKHYPIhRKNlc5J+DzE1L lKcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=uiUe6WVCm0aaHbhBXNo4kkWYKw5SBau4ovvcrSad9DA=; fh=6bG6dYgjJ0y4PAWYrYzXqN+AHWDi/B5SRmclIpk9oTE=; b=c/yuVZnxNaSW/r8PG8b7gBBPl5c8DCEY845ECZCapnI/YV/eOtzbkFOPgKOAeurDDp 2G5KR9BYeQz/ba60+0A8Mn36x+ZqfPXCH7tcZRbXjR6G3/JX70anO61q1vdjn93m9W8G 5hgTvaqGtB7jCFxOmnZmBJJ2TNIurEorjoAGFPc+PZVHyY2nZDaIvY9X7cTRM1w8kqd1 RV849t+WOv5isIpboaINmxbq9+Q7cGenxEGXghENzECEl9Xy0x4C1kQkSUOw83yrqdJW evDyw8tcKEjmVE67BDiCIhZzYCM2YotqVogtEVbrn/FUX7cVc6LLOVMbNHO+pDNSfrDt DhTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Yg1ptZ7I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id i22-20020a25b216000000b00d9a49bac80dsi5522718ybj.53.2023.10.25.14.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 14:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Yg1ptZ7I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4306980BA646; Wed, 25 Oct 2023 14:34:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbjJYVeU (ORCPT + 99 others); Wed, 25 Oct 2023 17:34:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbjJYVeP (ORCPT ); Wed, 25 Oct 2023 17:34:15 -0400 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88B9B128 for ; Wed, 25 Oct 2023 14:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1698269649; x=1698528849; bh=uiUe6WVCm0aaHbhBXNo4kkWYKw5SBau4ovvcrSad9DA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Yg1ptZ7Iu2gnfRFp2pWfcsbc7FROFS4YsR6RmgxZ2PNEyB71jVvLhP+ZgIt8dgDQ6 Wkd0PpRGoBIhtXEaw8saacjcjyLckAafe7bLCpYpvXSmkUZg2WwWBhggxckLuC0jX6 EugVoKUPe9Jfe/wp1BMqrYYobDUPRJdc2jazg7WbY7VwszxWMmAtIvZTH+l0GCKKv0 4QpnPyQOjeTr9CLWNBACO0sE/PfpLuPf87DI1RTGI/BiS9S4jA++5lsu3Cxq7K+L/g 8KzQHFk08/PFcGf8BXtX9MgUnYpBlaus8jPZBnt8zbO6uLaHyo2jAX1ULInJHjSsA8 W30LQWeP2ztAA== Date: Wed, 25 Oct 2023 21:34:02 +0000 To: Gary Guo From: Benno Lossin Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Alice Ryhl , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] rust: macros: improve `#[vtable]` documentation Message-ID: In-Reply-To: <20231025201445.497f6ef4.gary@garyguo.net> References: <20231019171540.259173-1-benno.lossin@proton.me> <20231024122423.383ea1bb@eugeo> <5c8b516d-323e-4a0b-8b8a-c0f0aec38b06@proton.me> <20231025201445.497f6ef4.gary@garyguo.net> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 25 Oct 2023 14:34:34 -0700 (PDT) On 25.10.23 21:14, Gary Guo wrote: > On Tue, 24 Oct 2023 14:43:30 +0000 > Benno Lossin wrote: >=20 >> On 24.10.23 13:24, Gary Guo wrote: >>> On Thu, 19 Oct 2023 17:15:53 +0000 >>> Benno Lossin wrote: >> >> [...] >> >>>> -/// This attribute is intended to close the gap. Traits can be declar= ed and >>>> -/// implemented with the `#[vtable]` attribute, and a `HAS_*` associa= ted constant >>>> -/// will be generated for each method in the trait, indicating if the= implementor >>>> -/// has overridden a method. >>>> +/// This attribute closes that gap. A trait can be annotated with the= `#[vtable]` attribute. >>>> +/// Implementers of the trait will then also have to annotate the tra= it with `#[vtable]`. This >>>> +/// attribute generates a `HAS_*` associated constant bool for each m= ethod in the trait that is set >>>> +/// to true if the implementer has overridden the associated method. >>>> +/// >>>> +/// For a function to be optional, it must have a default implementat= ion. But this default >>>> +/// implementation will never be executed, since these functions are = exclusively called from >>>> +/// callbacks from the C side. This is because the vtable will have a= `NULL` entry and the C side >>>> +/// will execute the default behavior. Since it is not maintainable t= o replicate the default >>>> +/// behavior in Rust, the default implementation should be: >>>> +/// >>>> +/// ```compile_fail >>>> +/// # use kernel::error::VTABLE_DEFAULT_ERROR; >>>> +/// kernel::build_error(VTABLE_DEFAULT_ERROR) >>> >>> Note that `build_error` function is considered impl detail and is >>> hidden. >> >> I see, we should mention that in the docs on `build_error`. >=20 > Well, it's marked as `#[doc(hidden)]`... Yes, but I did not even build the docs, but read it directly inside of the `build_error` crate and thus I did not see the `#[doc(hidden)]`. >>> This should use the macro version instead: >>> >>> kernel::build_error!(VTABLE_DEFAULT_ERROR) >> >> Is there a reason that it is a macro? Why is it re-exported in the >> kernel crate? The macro could just use `::bulid_error::build_error()`. >=20 > The original intention is to allow format strings, but Rust const > panic is not powerful enough to support it at the moment. Macro > allows higher flexibility. That is what I thought. But should we then not always require a string literal? So kernel::build_error!("{}", VTABLE_DEFAULT_ERROR) > It's re-exported so the macro can reference them (note that downstream > crates can't reference build_error directly). Perhaps I should put it > inside __private_reexport or something instead. I see, I did not know that they cannot reference build error directly. Is that some limitation of the build system? If it is possible to not re-export it, I think that would be better, otherwise just put it in `__private`. --=20 Cheers, Benno