Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3462699rwb; Fri, 16 Dec 2022 15:36:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf4xTASUmvAA0IFjLvoOk2CiCFs44BJFwdRo2Zllg65b4bvRwgLu1WKJuelrxVVvSY3md4Re X-Received: by 2002:a17:902:a418:b0:186:e8c1:f583 with SMTP id p24-20020a170902a41800b00186e8c1f583mr33560750plq.64.1671233766436; Fri, 16 Dec 2022 15:36:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671233766; cv=none; d=google.com; s=arc-20160816; b=Z/mepus9q8z1GBNXdj6a5w6Q9KVnJyCPdLW55px52j6TTdyDm7xui0m1VHjJij0CVk OjkiI43xAE9ygMl9WfWAqMXky8aR3gdPtQRiyeQNDXUvG5hvRF5LUgAJ0Y+N5HAuhpld VbwRPJLRcnwEx8vsiA/S/ivb3JqAkLcxo78/KrqcdAZbDFDMdAVzzKASg2Invkc7TUsE 0+RnuIuBaz1hfe65mZNuoCGTNr2gXL2n2y7E2xrQyaZbh3s6cH1pXriGEr1MxfBrbbVR 4NNiLGRn7bGLp/IvhO32sLz/K+VD3aGD4MumsL1O1X1nELPPpYlVqHWFHlTiyNwmaA5+ jEQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=O2TVu+3MfQCVc1RNPZura77WekzfqEyNct5iHB345A4=; b=M5gXaZhwb7FlJl0PXsRIHtsA/FAHCSrHVnEDhE+KeA3W7XBlzVMmuR3ZinBSMig0Nr 36kHPMyRafC6IJrWv8NMOwwe4Oi6D+MXIojS+MdPCxQ2DcCPu4qZbcQykhwuQDPVOqHx nj8tTNQzs7iSJoWrZC2NwfrEoDQow9nA0qChoPSJ+K1SJj5+IKik0ONflCqKmtULrX6U O8/kp221Q/gwRJAQkPZMLZ8eSWM/qli/SZO5I1074EVThdarSnpUHPOZgcdTCEbd5XBu KZmQc+BzLUobfWh/+7ohCKGeF+4FZ9SXym1vcx02qzmUt90bsIoK/mjOncKK9njzjQUX oUHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a170903024700b001890fdf32c1si4158778plh.180.2022.12.16.15.35.57; Fri, 16 Dec 2022 15:36:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbiLPXbI (ORCPT + 69 others); Fri, 16 Dec 2022 18:31:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230199AbiLPXao (ORCPT ); Fri, 16 Dec 2022 18:30:44 -0500 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62975B99; Fri, 16 Dec 2022 15:30:38 -0800 (PST) Received: by mail-wr1-f48.google.com with SMTP id h7so3955436wrs.6; Fri, 16 Dec 2022 15:30:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=O2TVu+3MfQCVc1RNPZura77WekzfqEyNct5iHB345A4=; b=VHRPyDeuANjF1pWwuUGyak9UFnLGKSo4arR4PYfyJOFjEJ73YZeilwq4d2IowtmZAJ JV+cnVN/YDuIs62uqD6WPXOmjjJuacIX3orXxlzkMEBtJwKWbL6Zdf4o1NvFZIgx8zTW OCuIm+1+i+IgtJgsvBBZs6i3pjqAM5NXwZmGwcRvaayi9fJkLu3N7XR31ktkEySWqGbF MiwyA7MyQdLEQKKUJDggbFUCMx5NsJdfrba+h6rJ4FxatnSDGiQGOozmwDLmRjho2xpP dbKx6CG6kks2hdJp4+Isy6CP7BxDFcfv8AUd/NDfOJOq3189XUfWKacI+fDwRZvWgiOs Ql8w== X-Gm-Message-State: ANoB5plNt4dS2hkGmpg1NKPFrYPyaOPtWpVnVWrNnSBZBluA8hhCtaYu uNMHLq+EhYoptNzKZuyyhcg= X-Received: by 2002:adf:bd93:0:b0:242:62df:9214 with SMTP id l19-20020adfbd93000000b0024262df9214mr25680980wrh.3.1671233436499; Fri, 16 Dec 2022 15:30:36 -0800 (PST) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id y12-20020adffa4c000000b002258235bda3sm3364978wrr.61.2022.12.16.15.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 15:30:35 -0800 (PST) Date: Fri, 16 Dec 2022 23:30:34 +0000 From: Wei Liu To: Boqun Feng Cc: Wedson Almeida Filho , Wei Liu , rust-for-linux@vger.kernel.org, Linux Kernel List , Miguel Ojeda , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron Subject: Re: [PATCH] rust: kernel: drop repetition in offset_of macro Message-ID: References: <20221216174927.1008629-1-wei.liu@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 16, 2022 at 02:15:16PM -0800, Boqun Feng wrote: > On Fri, Dec 16, 2022 at 06:26:57PM +0000, Wedson Almeida Filho wrote: > > On Fri, 16 Dec 2022 at 17:49, Wei Liu wrote: > > > > > > It doesn't make sense to allow multiple fields to be specified in > > > offset_of. > > > > Why do you say it doesn't make sense? > > > > Here's what I had in mind: > > ``` > > struct Y { > > z: u32 > > } > > struct X { > > y: Y > > } > > offset_of!(X, y.z) > > For me, it's not very obvious that "y.z" is multiples of token trees > rather a single token tree ;-) > > Maybe some examples of the match pattern of macros can help people catch > up faster? Like > > "y.z" => tt [y], tt [.], tt [z] > > I will defer to Gary or Bjorn for a better quick guide of Rust macros > ;-) > What will be even better is someone please contribute such a macro to libcore so that I don't have to replicate the code snippet everywhere. :-) I have a version somewhere, the second argument matches against ident, which was definitely not as flexible as tt. Thanks, Wei.