Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2787756rda; Wed, 25 Oct 2023 12:15:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaAiiVlXdfC6O6ndTmApmpFFdQuxAiHHCuFPV+gLmqyqhx8rD+wKzIUorc2Rrx1kp6NEoR X-Received: by 2002:a05:620a:bcb:b0:76e:f496:1930 with SMTP id s11-20020a05620a0bcb00b0076ef4961930mr18309636qki.43.1698261344735; Wed, 25 Oct 2023 12:15:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698261344; cv=pass; d=google.com; s=arc-20160816; b=xC3qiBdvhMA3+Fd56flqNzQP8DRWyLWFloim+lq2q9sR8wbfq6BZfkb2gPylapdNM5 49pkkMUP0lFTxwo65lc61rZmMaiH2deH81ycb9gnW/EFWT+rO30N1JVeCSRSPV3Jk0dI i6iqFaWl9kGnPue5VFW0Qe6jUi1NLzc0UU+oQ4+1hcfJfKPU7MOI6SF2rYz2a+U1oZMP KhT6oJfSN35tb5aQpPkpIIVu+A3WoSIJXX/VDQVQjnlB2crlJHaVJWHdL6p3tG/1YW0d xT/ZESa7I5nOo0uoanP2rm+GCkNcGZiPnDv2K/yHawK20sE6xG1gUck9MzgqEg7cndpn avvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=hXwU5DhO1jxWiorA6NUDVhGKvWjOznN+Lbnhm7FJViA=; fh=6Bzh4Uey/qjeRRXGmdFRnczmgve6eYJO8qlxg+sXrrQ=; b=b1ezHlHMWv1dBgijrzSd/KKWX9siv0s/ICg0LmbtqHO4OsQSLCivXJywto1+jmAyCx UY8mc6J1vcvZE/Zc6io2RU8C6Rg1qiTJ54nkw5JYJh/ZHWONplCsoT5Svm1I77WRdfQo xd9671juOXMsJABkO1qzJz2cNJQI2p4v7pdIP85+7dqTNfVxoF23GULQgExkNdkWgX/C mM2jjkf/CFokQk/cpQat6jkGKUrM5w8RP/gu3KHNhz2k9rFVSL8nK8NDRNTps+9Y+/iT uiDjLPUNCYzWwirfxB3OsLE6ou12D06CKQ2FhCdGRkY9XZi7cmecTcnsNdZcVyMepI8g 1tJQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b=OyDcK6My; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); 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 Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id y5-20020a05620a44c500b007742f841ec5si3190460qkp.383.2023.10.25.12.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 12:15:44 -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=@garyguo.net header.s=selector1 header.b=OyDcK6My; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 462ED806E5CA; Wed, 25 Oct 2023 12:15:08 -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 S229735AbjJYTO6 (ORCPT + 99 others); Wed, 25 Oct 2023 15:14:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjJYTO5 (ORCPT ); Wed, 25 Oct 2023 15:14:57 -0400 Received: from GBR01-CWX-obe.outbound.protection.outlook.com (mail-cwxgbr01on2115.outbound.protection.outlook.com [40.107.121.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E6E3BB; Wed, 25 Oct 2023 12:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iAWXF5YT7mfGVMF8heZKd+h+S8XuOjAs9qurUWn+lM1y5PWgeJWQ59FH7h2bGakLuR4BvLJylEEr/pfHU0ji/8TQYqekl6YX13EORP206HYPQKBZHqxj1kcaVS5cKcGGQrUEo8ND+jKtdpFL5m1v/Q2PRUjulSt3N4h1/50JNVHOW42v9TNc4YzzqD14LmwpVOoOWDt8RHttGNTxG2WEcQloBOWTFRBQQyMureql2iYDhHGpNIE/9iS0ncov6EDrT0xQgf4Pw7YQMpTvX6laDO0FcN1g/Lj4sfYaLrroRpBvUH3by0ji08byyYkdTH4YmGN9jeP5LoANQNdSJojDgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hXwU5DhO1jxWiorA6NUDVhGKvWjOznN+Lbnhm7FJViA=; b=PkRCp4X5ZWNguqlCfj6SL4T1DWpJWkrfjxjdxKgwgHFiJLVFpeO0qXmQ1ae6qh13cpDCbpy8HYfNbJKtWjVjKZTNpiQ+2EbkuvW7p5+weXm6JbCEZFT8259KiJKMGn1WmqIu/+m/AnqWewRqnRIeDTzy0tH37YMgNF2nY7nNOgSSD0E6HDvd2Nd0JLroF1UgcGpd97JwwsxVilekSIeRzyzeoWdTRxzqXUVE+iPiyIPyJJ1AsCWK7hxV1ds/qGNE2Dve1LDyCpt4vQ2JyJzbhTwz9OkdDA2s9lYeS4BZS06xaII/udqm7NoEM+wfDfxKfkrJlQPpjUrQJUJ+/2yPPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hXwU5DhO1jxWiorA6NUDVhGKvWjOznN+Lbnhm7FJViA=; b=OyDcK6MyFvtGYqr3J0BALMHR2hIi9tlQ7YmvWEJXsAPv+lAljtbqklEysf5JgtRnRbGJWuds3mbWUqqAb9CYMAivmDvYt3UkvmMooufiuMqZfxWe10mUVXCIWhJXjRYe8QhCY0dQ39E2fnXR7raUtxURyPffP4wPwy+1MmBGfZE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) by CWXP265MB1990.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:7a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19; Wed, 25 Oct 2023 19:14:52 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::6331:81d5:43cc:a9a2]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::6331:81d5:43cc:a9a2%6]) with mapi id 15.20.6933.019; Wed, 25 Oct 2023 19:14:52 +0000 Date: Wed, 25 Oct 2023 20:14:45 +0100 From: Gary Guo To: Benno Lossin Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , =?UTF-8?B?QmrDtnJu?= 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: <20231025201445.497f6ef4.gary@garyguo.net> In-Reply-To: <5c8b516d-323e-4a0b-8b8a-c0f0aec38b06@proton.me> References: <20231019171540.259173-1-benno.lossin@proton.me> <20231024122423.383ea1bb@eugeo> <5c8b516d-323e-4a0b-8b8a-c0f0aec38b06@proton.me> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P265CA0187.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:311::16) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|CWXP265MB1990:EE_ X-MS-Office365-Filtering-Correlation-Id: 6aa8031d-8fee-4dfe-c47a-08dbd58eaa28 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hd3XZ5btX7dGoEbiaTLmxYf/3w2M/QvG4aUPbw5cxhHCpXx2XMQu6avazGw9JxIK9BhazejVJO5r1NJwE2Kh5vD/ClFKfdYOn9skt+iMY4hYeIAdNTDVCkQbXLE0Jg1LHAxpkD0BWuVQaXkkh0Hk2Yw21mpSp+tBTa8zlir055e32tfbbIt/65JX9ShLVYb8yYB9jkw/YQyswEo44cl97UdECPk6DuEZs220oi4TP5y797L/RgiMKyMtvaRDKv2k0fgtZVEj9MKuECpHsIf25bQHZcRhuSCmaVfc38P7BaWS6Vr0z0PnjRwWZMLwEXHdY1oNc+QNrIbMhBNxEtuQ+MBRPYb1SH1l7XWq+At821OpAeiUS13ZEfm31idzhjE669eFdTHBgPODp5z6Vq//qLz2wInibNeJPJZBjf5hNo15RWJ1x8940QvyVKSSWW7LueQposcgXzFf+hstpTQwxYb6c/GXgbv2nAsinlYcpjCmWsW+YP5TvZV+pJ1iAkDxdRYsam5QKke8kLFvk79W0FaEOqvzMEMypj5xVx2EypFo9Q88dVJNjGwNVz6yMQTV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(39830400003)(396003)(366004)(136003)(376002)(346002)(230922051799003)(186009)(1800799009)(451199024)(64100799003)(6666004)(66556008)(66946007)(66476007)(316002)(54906003)(6916009)(38100700002)(478600001)(6486002)(86362001)(41300700001)(8936002)(8676002)(4326008)(6512007)(53546011)(6506007)(5660300002)(36756003)(7416002)(2616005)(1076003)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ds5sek4FYxUC+MqBF/MA1Mzz7Lp6v8PWp9jSVlibBOPPEEDMIx1mgTvKTUPo?= =?us-ascii?Q?RWVTQmnsnJ4LRa7foU5drHffPZt54l32RjPUiqw51B4EwyInzuOuLY0S+GSJ?= =?us-ascii?Q?qYDZETzcW6rPHFDwxypkg1Fg3MtG+Z2yiBdC9c8l8g0szZgKi3tXwwYdHTG8?= =?us-ascii?Q?B6IvIHM+60M0EpXBWO3OsAvX6ZtMu76H0qN3ZXfps039cYRXjTcc3xwuiz45?= =?us-ascii?Q?nZAaPgoZucuH/I9Hha64oeJFVAETOe/L5cd835r6YuXdTGWjvkrH09BRhHDn?= =?us-ascii?Q?dr5DSrcuV1B+XNAy3CXATIPqvSypPSLGoHKCeBg4ASToXh5bUSrvkH4kNvqb?= =?us-ascii?Q?lTeePndYhtIVCKTQcxzgwLZ3KVj2BH7X86jfw1S6NxyNOr5+Q8eq2kSqX9eJ?= =?us-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u4lFJRDhyU5+Y+3A8iq03i/uSkZ?= =?us-ascii?Q?rvisn4Z2/YQ4h7XspGIyg2scOCNMbgDk0cruSX56ckFUUAsYunKVr2m0iHUR?= =?us-ascii?Q?gS8UnDvT1yZ3EjIe9X1hRGtI2HieJcZbV7bfmB25Yb3SybPdZPzcfAqEQs2o?= =?us-ascii?Q?VmhxoDdXdkUyqNqWut+h/omO9bUBiwGiu9O8VZtHJIbhTUmW+Wzu0ZtJKIyu?= =?us-ascii?Q?9UGtaosbBPIZNFUmcTYZ5UW3QO4aKwncXM/epi3EQHT3h20KbWpwqF15Pksx?= =?us-ascii?Q?AFX1mvgNafxrkfsNHg5arj6Sg1UCvrFrhYqAAHplM2hNiEhAaARWrH4iRKIQ?= =?us-ascii?Q?FGK4OrmLGFvaCeG4XRORRahq3G0HEtT2uSflonM6PEEC?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 6aa8031d-8fee-4dfe-c47a-08dbd58eaa28 X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 19:14:52.2163 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: n7Thb8D/BjJ4RstgRL+wceKGiIpcWJUqTVpW9z0nvmF71+MZH0CUB9eI/k+99MPEMqzNJS5d/g/J3JYwi9IErQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWXP265MB1990 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 12:15:08 -0700 (PDT) On Tue, 24 Oct 2023 14:43:30 +0000 Benno Lossin wrote: > 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_*` associated 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 trait with `#[vtable]`. This > >> +/// attribute generates a `HAS_*` associated constant bool for each method 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 implementation. 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 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) > > > > Note that `build_error` function is considered impl detail and is > > hidden. > > I see, we should mention that in the docs on `build_error`. Well, it's marked as `#[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()`. 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. 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.