Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1936819rda; Tue, 24 Oct 2023 07:44:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7pDMVzi0xLa3jM9jFUkwVBfBRjmv9Npqpc+EPy2nzXNOTvb+Ag3QYdBQo9eiAR7lqSoQb X-Received: by 2002:a17:90b:1490:b0:27c:edd5:6137 with SMTP id js16-20020a17090b149000b0027cedd56137mr10016208pjb.25.1698158642714; Tue, 24 Oct 2023 07:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698158642; cv=none; d=google.com; s=arc-20160816; b=iYTxlC/pCRWYdbhYcBOQTGySHqj+ZuDxuD2Tgd+FLi00SVWwrWYcdHTerrkgGdYbrV ewmkcX0xpj0X/s+rUxWUJl6oaPIUQLEZxhpQjRZh/2AkYgUURri5PaVbFgj0Ue58E9b0 N0/8H9AICadtkJQtKdxDMrd4w9lG7rcq6z9lXqNTDeaecEW+0xldFegF5S+ZpC0ImSYw B/yMMx2O/N9g/EPVePJi0Wh8nIbcsTymBEz611QhXQtQzO376tcBkr81w4a+/tG9CJPj GWYuOM2XFV0+GNRDAEw1CxP9v5xuQJqu/YHzIuqveZHotoG6equLPNlXimt9uWHuD/a7 hBZQ== 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=upzx+nk01+m+EwuBULbIelOm8X3Ott5WP7auABbMUKk=; fh=6bG6dYgjJ0y4PAWYrYzXqN+AHWDi/B5SRmclIpk9oTE=; b=KT+MU644emNqZXW0n4UPxUDcF+HHRbRDj8CRFHSoOvzbrBq+c299Jw0azMnNlSTo0v t+MgYtX17r8N7Y9XSf3+/MvrSJAENGHxG5HAVzPxP7gpYJS6UxVUrZXOpqtmxDuGIMY+ YAo7/r0ms6U0Wlv7DKWBK3ZFesLsGCYnq6ioSO2p1o9Ul707pUvUW1kyxeRkY6KkzAqM 4dHV5gFcFsRQvejORH1zzFv9iTS1qm1ee6nEoQLomNKnHCxbtD6QSD7vOFVytKxeGIh1 O1mEbYz8ycf/ZUp9MYUgw7jcfgmd9KqNiEokSAQ91H75DMFDdnsqkJryta3rb3tnLRpO Hw/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=SvCIcY9x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id mj19-20020a17090b369300b0027748734bb9si10993723pjb.148.2023.10.24.07.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 07:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=SvCIcY9x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id BADC68051B35; Tue, 24 Oct 2023 07:43:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234483AbjJXOnr (ORCPT + 99 others); Tue, 24 Oct 2023 10:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234469AbjJXOnq (ORCPT ); Tue, 24 Oct 2023 10:43:46 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2368BB3; Tue, 24 Oct 2023 07:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1698158621; x=1698417821; bh=upzx+nk01+m+EwuBULbIelOm8X3Ott5WP7auABbMUKk=; 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=SvCIcY9xGbgUACmraTDg3j1NS0aPmYeOjwq4uFNxdblqw4mAzNJX1KY421GbExel/ sPz8P2dpXLIpxLxfQUQ4i94iwiIu30aek9frBJnkBtK82PZPhUsfEq7eLv/2Fuf2j6 VznNSGa+d0CIHClFKkcYOfH08b1DledRUNtpWKF3FHO8G0KE/A2mnTbIhmHEWKohUc 5A6JV7tBJ1mYg2iOlcYM8e06vqw0MNCqUDOSSJdDhoSZ4NW9HfHD7V/fR6YPOWrYLr 4d5oIZSkSs9+d8pDsQ1Z+DVv+mTym5QwEhIl2IIOKmwsn+nq8mtp2GX0QEnQ5Zou5c o+1zUfFYhUBBg== Date: Tue, 24 Oct 2023 14:43:30 +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: <5c8b516d-323e-4a0b-8b8a-c0f0aec38b06@proton.me> In-Reply-To: <20231024122423.383ea1bb@eugeo> References: <20231019171540.259173-1-benno.lossin@proton.me> <20231024122423.383ea1bb@eugeo> 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 07:43:58 -0700 (PDT) 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 declared= and >> -/// implemented with the `#[vtable]` attribute, and a `HAS_*` associate= d constant >> -/// will be generated for each method in the trait, indicating if the i= mplementor >> -/// 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 trait= with `#[vtable]`. This >> +/// attribute generates a `HAS_*` associated constant bool for each met= hod 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 implementatio= n. But this default >> +/// implementation will never be executed, since these functions are ex= clusively 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 to = 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) >=20 > Note that `build_error` function is considered impl detail and is > hidden. I see, we should mention that in the docs on `build_error`. > This should use the macro version instead: >=20 > 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()`. > Actually, the string here provides little use other than documentation, Sure, but that is the whole purpose of this patch. > since the string provided to build_error is only visible in const eval, > so this you might just omit that and write >=20 > kernel::build_error!() Note that it is also useful for people who read the code, as they can search for the constant and understand why it is a build error. --=20 Cheers, Benno