From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CWXP265CU009.outbound.protection.outlook.com (mail-ukwestazon11021106.outbound.protection.outlook.com [52.101.100.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BBAC74BE1; Fri, 13 Feb 2026 09:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.100.106 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770973633; cv=fail; b=NPKUdr+8HZekeoT8O2OPRxJHtG6ecHJycJSSLY44VhjZs+xHMjvSUCFLk7UZAEu5Zq2Kqv6E2LE6l4p4FaGCNPcMVqVrrbubHsDi7hHgwMduRYNcwKxwNKqE5nLnfBmmhuyGD2Nj8xMIEOEubRc/xUzbS2IEnUvtKGNFDeAs/hI= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770973633; c=relaxed/simple; bh=HPWMfoj/hiNc+bub6YF+Gh6xecPOumiaOAMiSus9FgI=; h=Content-Type:Date:Message-Id:Cc:Subject:From:To:References: In-Reply-To:MIME-Version; b=XC8vZsE+msce0Q6VoURkcNYT6QhCDbdUfrZNhOUd4hw7S+lD98BLdeuyApxwDIGZn45m5aXWvjpXoC43dpIKFgovCs0rFxo+9w7yPwtBrTvVaA1ZtrGVBfYNHYVluTEbbwl+TATJZbkVorS1kFuKqPtZWEHxKtZelOTvseFz/B4= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=mZVTj6K3; arc=fail smtp.client-ip=52.101.100.106 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="mZVTj6K3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DxSh+nmF3SH6jnSIzg1TmrNvMJHSiPckBy12+4YCRSRiD/azwGSckrqDS2MUoNowGbwfMHLqCxHYT2yNtWgz/3oo8TKFw4088BZIXxatdMe6igJ2r/+ZJCzbqVmnRLjpi8tYm12xJhd6lbmayrrmGM+3wGOrQxsRMB55XEZ8jlPEK3qMBKk6tB29YZam/Uhj2JPkUSqOaCeIsNKimFu1Q+cRmc1FDKpd+RKKsJ34CQ9NfkXbuS8nMx4ukbjofA6mt/CtXkcdat8krPl/bXa4Y4GhDKtfvv7eZZlvjHk32RKVkyBtebP/z6Pvs+KB8KTlT1AUdiMEw00bJFl5NnaeDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=o45D2x4i/v8duUnjW8mGDGIxrdo6QtuH0l29BTXcjCY=; b=JK68QRIj3fNWGjx6IxycCmcGMdYq98OWZ9BZHA4+Cp5bq6UqbjEqvgvjGw7Dp0mgX8/m1FdP+7xgxquEdXsnCx/ofcL645MBNBge2ajacRNvcbBpDkiLKlYMQvLOwvkUzWRk25TeN1WxGYfnZJ3KBJBxHYVKi3t5Smo75idldOa5kMRQ6q61QHypcxVQLIQICqff3TkxxcmXWLInod1jIXG82BSXSBp+i4Q8exvFJayQgbngpkCm2lBk2NRwPDbBy5NLbzROmQAYai2H4q8nsrnE335pmT1LyApzWFyl31q4vRGGONmWDq/uDjeu+ansW0mWKxZi7OvK7PV2GGSgLg== 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=o45D2x4i/v8duUnjW8mGDGIxrdo6QtuH0l29BTXcjCY=; b=mZVTj6K3ewLFdzoUlKRo0mGK+RCDYMO7OvKzYNmxj/AA6udopGbJxP+aC1geFH1/RqikFpO3c/gZgI5XOhuQTW19qHHLb80VR2C8OC8kcN1/UlKZJjx6OiHctPdxOcyxUaxXSUmU5QBZOCMDYGsZwK/Vww9Ss2XCcjs0lF7hXQ0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) by LOBP265MB8438.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:46d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.13; Fri, 13 Feb 2026 09:07:09 +0000 Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986]) by LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986%5]) with mapi id 15.20.9611.008; Fri, 13 Feb 2026 09:07:09 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 13 Feb 2026 17:06:54 +0800 Message-Id: Cc: "Miguel Ojeda" , "Boqun Feng" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Alexandre Courbot" , "Yury Norov" , "Nathan Chancellor" , "Nicolas Schier" , , , Subject: Re: [PATCH 2/2] rust: add `const_assert!` macro From: "Gary Guo" To: "Yury Norov" , "Gary Guo" X-Mailer: aerc 0.21.0 References: <20260206171253.2704684-1-gary@kernel.org> <20260206171253.2704684-2-gary@kernel.org> In-Reply-To: X-ClientProxiedBy: TYCP286CA0297.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3c8::20) To LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LOVP265MB8871:EE_|LOBP265MB8438:EE_ X-MS-Office365-Filtering-Correlation-Id: ae5a46fe-39be-4123-f301-08de6adf442d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|10070799003|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?Rk9ETHp6WEIvenBGWGlGNEV1RXVXbktZb1FVa3daMzF0SEwrRklyNm5UOFk1?= =?utf-8?B?QVlwaHZhN2pZcW5welVGanRlc2ZrbEZIbkVIWnk0U1BpL2VvZnVtOFVadlI1?= =?utf-8?B?aHhVRGpOdjRCcjlqaVd6VjNuL2RqSWhpN1czeUUzYnJDWVVBYmpZaEN2UzhN?= =?utf-8?B?N2tEeGc3cUM2Wlk2Mm4wOXJjU1RuYmJHRlRqdTNLUWlQN21sdGpWNko0VVdR?= =?utf-8?B?QVEvdndUWTMvelZENTVKZVR2YVpYcUVqcFZPcGJqaXVKSEhweUMyem1yUE5R?= =?utf-8?B?TFJIMHhNMTg4eU5NSnk4anV4MUY0T1NJd1VYMEMzZ2NFTEMyR3ArV1kxcHBX?= =?utf-8?B?dEpWYUZZWUxIWWRZWHQ3bUFQWlV6UjI1SGpPUjUxY2luWXRLcjVidnVBTi8w?= =?utf-8?B?ejZUYVVLUEZyQ2VQVVhIYWgwN0t0Z1hYdGZLenhUUkxiYWltV3QzN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o1MkNUdkpYdFdj?= =?utf-8?B?cDU4RW5mL0gwbzFQODU2S1dacmhhdG8rYVcrRjk4eVJwaG43RlNFZTVaUlFa?= =?utf-8?B?RnVDeCttOUdteGs2eXlVNEZIN2FZQ05sMkpwT09EdXg2UFcraE1TK0srT2hB?= =?utf-8?B?M0dZSk5PVGRMbkFnckFXWUpGVDhPWTNMQkNDNUlGQ0NFUmtxMGlxQ2gwSG8v?= =?utf-8?B?cklXVmNWcW1xbEJTekJXaTFPNjRqTHFHc1lCL1VZQ2o5MGYrejJDKzhWNFN1?= =?utf-8?B?L0dvdTRCWFRaMkN4ZElUemkxanltaTExRGx6K1ErVlQrYVo1NEZDeHI4VXBP?= =?utf-8?B?Umh6VnVXQlVkUkk4S0YrdXZycDBRVHJUbys3UlhVYWE1U3NFMXZEdlNxVXFV?= =?utf-8?B?d0tLZk9scm9wMnZtWll6MytJemxGb1VsTUxBZkJLdVpWRmpERG9NdWZ3dmpU?= =?utf-8?B?Z3VocjFzaW9DTENJWlZORWNwWDk2Y0gzb1ZIRmg0WTZReEhUK1hYdTBrMnhV?= =?utf-8?B?M1FzRFlSa2F5TC9ZQ2pUK1l3aEd4NHNyQm8xb0RaLy9pa1N2SW5pdEpqYXpI?= =?utf-8?B?Vm9DSTVCR3llNDV5ejdEOXJrUnRrZ0dxSDJVMjNna3VIUE0xZzVFT1QvNUYr?= =?utf-8?B?NUloKzMzTUx2UnpWd21QT0xZQXNaTzBkenk1NmxhbWNya2NaKzNiNEZveTcx?= =?utf-8?Q?lPc1Ct?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(10070799003)(366016)(7416014)(376014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dm1Y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2NlWFA2?= =?utf-8?B?amYxUHdxazFTWmtJU1M4YWxYYUw1bkhGaVBNRXhNa2FyTnRQdE5Fd1FseEhW?= =?utf-8?B?S0kzVjh3WTh3Q1ZZeFVsb2lpWjVKd0NNaEl0cWt6QVI0WCtGUS96NHVTNHpP?= =?utf-8?B?Mm9jZU1GNithTmdMMy9WcnMyajU5UW5kallqYjZ5THRlSk5UL25ycGVHSE5J?= =?utf-8?B?UWFDdWtTbVBDdnFWU2JkWmZwbHhnZkFzUnd6MHVZTDNsSDQxd1NWeUx2VzI4?= =?utf-8?B?K1U3bHFndmFjOHorcWdCRWkxd1pCZStLR0JBQnAyMUdKY3NMVmJVUHBkN05p?= =?utf-8?B?TFBYSjVDTjB3UGNQZnJVNHhyY280ZUgrMUMwRG92VWlIVHZKS1E4ZUxldGIz?= =?utf-8?B?UU50S3lSdStkR2xIT20zbCtEaEN3Y2d4UHRqUDdHczlWYyszdGRZR1V2MUcv?= =?utf-8?B?T0d3a3ZTeDFIQlRqcU5QdlplODlUaW1zMmIyTHNLZE4wTGlFdXFlY1NwemV6?= =?utf-8?B?MkhyeTJJNW5uWklhZnFLOUw4RGk3Uk5XWGQ0OXAzWGFVT3JtWGQvdSs4KzBQ?= =?utf-8?Q?WLjcKMpe2H31EHrjG1Nb7XTDoHysoJfVyFfBz?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: ae5a46fe-39be-4123-f301-08de6adf442d X-MS-Exchange-CrossTenant-AuthSource: LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2026 09:07:08.9389 (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: 26z+DFdH1c7xIidF7JElLteHMFV5NrpSTPeqh3McPPWUZBxT3MBb7wheEYsLiKxNdTNh4CtPV8tLNZdqQGZFpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LOBP265MB8438 On Fri Feb 13, 2026 at 9:16 AM CST, Yury Norov wrote: > On Fri, Feb 06, 2026 at 05:12:50PM +0000, Gary Guo wrote: >> From: Gary Guo >>=20 >> The macro is a more powerful version of `static_assert!` for use inside >> function contexts. This is powered by inline consts, so enable the featu= re >> for old compiler versions that does not have it stably. >>=20 >> The `build_assert!` doc is refined to recommend it where possible. > > This is a good place to actually explain where this thing is possible. > =20 >> While it is possible already to write `const { assert!(...) }`, this >> provides a short hand that is more uniform with other assertions. It als= o >> formats nicer with rustfmt where it will not be formatted into multiple >> lines. >>=20 >> Two users that would route via the Rust tree are converted. >>=20 >> Signed-off-by: Gary Guo >> --- >> rust/kernel/build_assert.rs | 55 +++++++++++++++++++++++++++++++++---- >> rust/kernel/num/bounded.rs | 24 ++++++---------- >> rust/kernel/prelude.rs | 2 +- >> rust/kernel/ptr.rs | 18 ++++++------ >> scripts/Makefile.build | 3 +- >> 5 files changed, 71 insertions(+), 31 deletions(-) >>=20 >> diff --git a/rust/kernel/build_assert.rs b/rust/kernel/build_assert.rs >> index d464494d430a..e40f0227e1ef 100644 >> --- a/rust/kernel/build_assert.rs >> +++ b/rust/kernel/build_assert.rs >> @@ -41,6 +41,45 @@ macro_rules! static_assert { >> }; >> } >> =20 >> +/// Assertion during constant evaluation. >> +/// >> +/// This is a more powerful version of `static_assert` that can refer t= o generics inside functions >> +/// or implementation blocks. However, it also have a limitation where = it can only appear in places > > "However, it also has a limitation", I guess? > >> +/// where statements can appear; for example, you cannot use it as an i= tem in the module. >> +/// >> +/// [`static_assert!`] should be preferred where possible. >> +/// >> +/// # Examples >> +/// >> +/// When the condition refers to generic parameters [`static_assert!`] = cannot be used. >> +/// Use `const_assert!` in this scenario. >> +/// ``` >> +/// fn foo() { >> +/// // `static_assert!(N > 1);` is not allowed >> +/// const_assert!(N > 1); // Compile-time check >> +/// build_assert!(N > 1); // Build-time check > > In the other email you say: the assertion failure mechanism is undefined > symbol and linker error. > > So, maybe: > > const_assert!(N > 1); // Build-time check at compilation > build_assert!(N > 1); // Build-time check at linkage > > Because compilation is a part of build process, and referring them one > vs another may confuse. > >> +/// assert!(N > 1); // Run-time check >> +/// } >> +///=20 >> +/// >> +/// Note that `const_assert!` cannot be used when referring to function= parameter, then >> +/// `const_assert!` cannot be used even if the function is going to be = called during const >> +/// evaluation. Use `build_assert!` in this case. >> +/// ``` >> +/// const fn foo(n: usize) { >> +/// // `const_assert!(n > 1);` is not allowed >> +/// build_assert!(n > 1); >> +/// } >> +/// >> +/// const _: () =3D foo(2); // Evaluate during const evaluation >> +/// ``` > > This part confused me the most. But after all, parameters in rust > are never constants, and even if foo() is used with '2' only, it > appears to be a non-constant from the const_assert!() POV. Yes. For example, const fn foo(x: u32) -> x { build_assert!(x > 1); x } require use the `build_assert!()` because it act on value `x` which may not= be constant, as `foo` can be invoked by runtime code. Therefore, body of const functions are not const context. However, they're = still restricted to perform only operations that can be performed during const evaluation. For language lawyers, this is the reference: https://doc.rust-lang.org/reference/const_eval.html > > Seemingly, there are only 3 objects in the language that can be > specified with the 'const': functions, items and generics. And > const_assert!() makes sense (doesn't break the build) only for > them. Very close. `const_assert!()` can act on invocation of const functions on c= onst values, but not values inside const functions. So in the above example, `const_assert!(x > 1)` inside `foo` is not okay, but `const_assert!(foo(2) = > 1)` is okay. > > So, the difference between const vs build assertions is that const > version is only applicable to a certain type of objects and is > supported by language. Correct. > Contrary, build_assert!() is not a part > of the language and in fact is based on a linkage trick, while > allows broader set of build-time expressions. The reason that I want to omit "link-time" is that our `build_assert!()` *c= an* still be checked before link-time. Again with example above, user can write static_assert!(foo(0) =3D=3D 0); which means that now `foo` is evaluated by the compiler. When this happens, `build_assert!()` also abort the build during compilation time, not link-ti= me. Best, Gary > > And altogether they make sense and even nice. > > Can you please consider to add the above passage to your reply in > the other email, and place them in the documentation? > > With that (or without), > > Reviewed-by: Yury Norov