Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7773078rdb; Thu, 4 Jan 2024 07:18:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1KffOtiytf+BGBdIXLjhzHiTUDGaulkiZK4qtmpbasG1fJ8uV23TKDv2c5KD+JtDHIeY6 X-Received: by 2002:a17:90a:fb51:b0:28b:fdf0:6aa7 with SMTP id iq17-20020a17090afb5100b0028bfdf06aa7mr596821pjb.51.1704381507826; Thu, 04 Jan 2024 07:18:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704381507; cv=none; d=google.com; s=arc-20160816; b=BpeaSDyCGNFD9q1nCf5cZ1NXzMENnf1m4Tvy8bYBUL9v3O3aTO7Njv4IHUuL49liQZ MMAPoF4fwIsQ0/ILAFUC12J80d/jphvQjJGxu8w1hwUstbYxl0eF/9E31/h4y7VtdEZ6 SMOvRCWCYVgWH0I+F+qEJmGQV0nZ8doNYaPqjnfXi6C6q59CiaD4Vch0NSl1ZLqirlwE 3l4fDmk8YVo9ZSkbYbwBlSR+yO0RrRXnY53WPbt9HHdwJ6RQf9cELNmr+uMlwmrRY7wN L4KFKLAGareqpQVsSSd9BpcgIuqCnS3V5iBxUZj0eVG35Ov9/yCCgvC3XKPiyuZbrmdV wM4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=nZwnS2Sp7vv2PRnAVDjhBATPiqXuD/DhpKZdALVjptM=; fh=0iDG5571Aeu2ImcNjH2puUvF+Y2TBkBvf/FcJ5ccl+g=; b=meQAzj5K7Ct7+Oec/RQ5OIp+S7QxS4f1w9pMACHRpnJVL/TwKfcFWUvbhKtq3yobgV FueUgSOHe+QKzwNgedW5sSxgedbukYckYxtk/hgPPQO0gVYMYCeuyXNEg+7+rsVhoM4A 4n5KCgbhW1CvADRSSWgSf2yxhOUo7wL8C4mzaexECOC7PoI5edh38n4dlOj2O7i+CsX0 ER2kyE5ldl/xuByT5/J0d6iyaECN+Dr7LbrDP82yXmfLDPBNB+D3x0/NxJIH6xbMLQ4M UBsEx4saOMAO91kQ3rilOz+KxPPCyZZn7aboVVX3Io9q9zcvk/Os3KUP1tTiRs7Ychqu LgyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rCAJ3Bvk; spf=pass (google.com: domain of linux-kernel+bounces-16843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w11-20020a17090a528b00b0028bd42e0ca5si3034794pjh.176.2024.01.04.07.18.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 07:18:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rCAJ3Bvk; spf=pass (google.com: domain of linux-kernel+bounces-16843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 67813B2118D for ; Thu, 4 Jan 2024 15:18:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1AC52241F5; Thu, 4 Jan 2024 15:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rCAJ3Bvk" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0465B2376E for ; Thu, 4 Jan 2024 15:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-6dc02727c62so327783a34.1 for ; Thu, 04 Jan 2024 07:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704381491; x=1704986291; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nZwnS2Sp7vv2PRnAVDjhBATPiqXuD/DhpKZdALVjptM=; b=rCAJ3BvkuCa7svBTTM856xsJPAk0VrRSewLOS76ssEEYFUMLkOQKxTAhEfU/q4F9nx P1hlyurUeuklxdcXm1cr+3xtujrxNuKtkXt6qrqTeKFc9NBlPGEQOIhrXh0Oc3Xj7NOc YqZEqqfqfVjgQnkwQERoXncM31CR/OPaiQThbiLF0VOx/n+YdoZ2UDpOOFVz2PwDWswD g4JwxUNMwTxZXt0LiJeehubl4+x01WCUckMz97O+d3Ft02NeEzIAgZVNv6y4x4JnUGlS /VcwPGI1LxQJZF3u2cZwTwyf/GKqX6rMz53BQBvD1diyBkrkUqElCd1mayDsfh6DgM4c U51w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704381491; x=1704986291; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nZwnS2Sp7vv2PRnAVDjhBATPiqXuD/DhpKZdALVjptM=; b=mRwN/LaWLsMGQo6/bx/xy24KH6IucBjRgFOoO0vTlGnFcxiTpOL2P0pDgGYrSIQyqS ae0w+nz73WaMwmdTE7ATDN+b/Ihcj/TDSKQmEKZ+/iRBnF5dk23QQkcc3VkqYTZtlx/E za86OJ41edNX2ccaPk85QKoMAenAxbvo/dsmbGvOAfhcYJgDtzpDb4p3fljsimSpKGvv SLuCZhKF9nfG7fohYdSJCxYf/hAYeRNYc96hx7cA+6ACdv9tVyTz7bffuAGOYQiL1j+F 4F7GM9AUNj4FkwMib5oydfc32ql96RzDucrOztSbG0xIsKbpYkigzvp48fplR7w0Xeuk 1LJw== X-Gm-Message-State: AOJu0YwHdGfipshoKneDIWdQZZJJ7hn4NY+WGm5dszv+IbH/T5tTqf+i NtDTxtl1XY00ThPsKcDrcGWSxKNK0NxgvOOGTni5/XGkEK6X X-Received: by 2002:a05:6871:4e46:b0:1fa:f508:b5cc with SMTP id uj6-20020a0568714e4600b001faf508b5ccmr722750oab.55.1704381490990; Thu, 04 Jan 2024 07:18:10 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231213220447.3613500-1-benno.lossin@proton.me> In-Reply-To: <20231213220447.3613500-1-benno.lossin@proton.me> From: Alice Ryhl Date: Thu, 4 Jan 2024 16:17:59 +0100 Message-ID: Subject: Re: [PATCH v2 1/3] rust: macros: add `decl_generics` to `parse_generics()` To: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Sumera Priyadarsini , Vincenzo Palazzo , Asahi Lina , Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 13, 2023 at 11:08=E2=80=AFPM Benno Lossin wrote: > > The generic parameters on a type definition can specify default values. > Currently `parse_generics()` cannot handle this though. For example when > parsing the following generics: > > > > The `impl_generics` will be set to `T: Clone, const N: usize =3D 0` and > `ty_generics` will be set to `T, N`. Now using the `impl_generics` on an > impl block: > > impl<$($impl_generics)*> Foo {} > > will result in invalid Rust code, because default values are only > available on type definitions. > > Therefore add parsing support for generic parameter default values using > a new kind of generics called `decl_generics` and change the old > behavior of `impl_generics` to not contain the generic parameter default > values. > > Now `Generics` has three fields: > - `impl_generics`: the generics with bounds > (e.g. `T: Clone, const N: usize`) > - `decl_generics`: the generics with bounds and default values > (e.g. `T: Clone, const N: usize =3D 0`) > - `ty_generics`: contains the generics without bounds and without > default values (e.g. `T, N`) > > `impl_generics` is designed to be used on `impl<$impl_generics>`, > `decl_generics` for the type definition, so `struct Foo<$decl_generics>` > and `ty_generics` whenever you use the type, so `Foo<$ty_generics>`. > > Here is an example that uses all three different types of generics: > > let (Generics { decl_generics, impl_generics, ty_generics }, rest) = =3D parse_generics(input); > quote! { > struct Foo<$($decl_generics)*> { > // ... > } > > impl<$impl_generics> Foo<$ty_generics> { > fn foo() { > // ... > } > } > } > > The next commit contains a fix to the `#[pin_data]` macro making it > compatible with generic parameter default values by relying on this new > behavior. > > Signed-off-by: Benno Lossin Tested-by: Alice Ryhl