From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 D7A913A1D2 for ; Wed, 24 Dec 2025 04:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766548816; cv=none; b=QS6OLdz9PdNKHe609QJielEctHF0kRTdoTHRmT07/Sqts6nJIuNSslBM7MIe86ctKrCTJ6YYb54b14+6OpMsPysfwZAv44PhHTRTxANtQAZdVnJkQRn5oPcdkGwRxNPaNNFGr4FLEQ6OYPMHCQQ3poe1l6hJ9Acs15p0nOpUUNw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766548816; c=relaxed/simple; bh=fbaJyRDiHq5rT+aHmP3nj0gx6DyyC4LXn3X/Q7G0qbE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ruvUPFoMeavFKQx1LJspCl/tHnoFeze516rytcGSsy9gbG/J8ums9lTMspqsfkZE0FtEDeYXLAuOwXP33LdWJwl4qA9NpaS0THRCC/btdipepp+sM8oLfiMb2VdyM4t0Hc2/aKZXYf/tkX9v+0oQSr5Kqjn9uoNtA+IJTHqi05M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MMOfWr7r; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MMOfWr7r" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7b80fed1505so5899893b3a.3 for ; Tue, 23 Dec 2025 20:00:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766548814; x=1767153614; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=15J8JYA2RlXsm9mHy/0N0w8q9AM25fubVC52MXcxDBo=; b=MMOfWr7rE1OC2i/Q9+HRLTTOgTtqoX+nXjgCUub0d3RHw0ETEeKtN6Dt6x1BXPidXY CaJ3Urhs7HFhmlRkc3sVbrx86/J/uJSb1GJrNDJXFnqAzYYjdmDMPqEE1M9oUM8ByE/N cYvCYEn6bKDc+Jmio4U8SWvphrwXaPcW46fAlVPd2niGaFV7Fm1YBxwvVZKIVqhCwVw9 hts6MrxymCEt4hZwgiJL9VxqMeL2lmx22kxl8BPbj7ZeiXCNd7PxoYRasxksAM57fe/4 mV7Zf0zVbHNniNVhMpsRFqy2I+atntSJWjBWyqWPUy/9mVmHxdSUsmXwOE98W7ZaU/eV 4mig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766548814; x=1767153614; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=15J8JYA2RlXsm9mHy/0N0w8q9AM25fubVC52MXcxDBo=; b=xTuTuetDQvodfYd+oepYZBXCRaXKtZ7RJOrERtQVZNn22GKvZNbHu8xUq5DGS4LVna AqbwkLGbmz6zEnalhTBF9uGSbNJxvIHD+oAk0TPm2SIqwjYsEGw0Sj950bGFbbgfhIys jA/GhdP7BIJUuvwdPy/UU2I0Z4WGPOxNKWWvHzF0jZxX2lasbISjU4rBz2Ji5NQcyhNK SVIKoJ9LjhxH83pA1l/RA7+diEACvlUvJFaKnkjjHRCtaf3cPVtLYGBLrzZAkMGVymYj JSgYXpy3RxsuOrY8wf2VIK+FbDbWn9mWbfago2Y8DIywkDmLFwUQzCtaVrepcvJDWW1W WThA== X-Forwarded-Encrypted: i=1; AJvYcCVmVdx8HnubvXkzqOfOuuuWAyEgZo0OVvVCjjmklJt8Ow4AISXeWbIxvQ1rzWNDhqvVz9pwvW3C9JuMmnM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6mqGRKeiWvT98tocYmB2VhiFDZ91wj4dP/VAJ2wdUsK93xmtm 97jbbDO9mLV8ZMrFLTTJywQ2vtGTjQiZIKG/MFbAjcN+oJ9RHqqRoteY X-Gm-Gg: AY/fxX4UHTq5ALLyeeoqYfuLTQgVkmHPb1PViUPjgaKnt5SUb/ykvEAKFMETxTZtZ84 HG9qUGm/iZ03JFF1oLBXO21OHZfLlIDBfGWv6290AKirJkNQlZe61crEx2+fJ/NIcgIZjVu73se MOHlryZHjZgY0aT8Yb7QoKI1mmlwQAMEQo38BdNlFSW6m0NIYkXDoBznzSNDVkOzC7c0ZqTPV40 ZbZA1s+6kDZwh4bG0uJ13wdQhaIRZzR55yP6eVGHw2QsrOL9pyHeT4yeP3EcQYowfkro5yfV8Yh c/I/YWhwVwhSS9ZVdZ+mkzPb1Sw905LAeMGXbmO8zKWDuu+3grJ8bqL8SRGwakurpeke6r/qWKo UnsCxR3hN+pfKUWAXPLaUfvFzeKCrMk1pH+jMjBS9pa4GxEsOJkQ93QU/zg9I438Aw6PEcDtZH8 9yyD8qnj1Q1ybnVr/c0Md8Ug== X-Google-Smtp-Source: AGHT+IFC5XGfwJjNkSwGpC2zGfaXAO1oe8q/u5Cyg28/T7qLlNT6jf0HIuXTN3KWVdXR0G5t+GJGFQ== X-Received: by 2002:a05:6a20:a11d:b0:34f:b660:770d with SMTP id adf61e73a8af0-376aa8e66e0mr15888978637.55.1766548814049; Tue, 23 Dec 2025 20:00:14 -0800 (PST) Received: from localhost.localdomain ([104.28.249.217]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c1e7c5307c7sm13255131a12.28.2025.12.23.20.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Dec 2025 20:00:13 -0800 (PST) From: Jesung Yang To: Alexandre Courbot , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: rust-for-linux@vger.kernel.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Jesung Yang Subject: [PATCH v3 0/4] rust: add `TryFrom` and `Into` derive macros Date: Wed, 24 Dec 2025 03:59:53 +0000 Message-ID: X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch series introduces derive macros for the `TryFrom` and `Into` traits. Primary updates in v3: - Adopt `syn` for improved macro parsing. - Allow `kernel::num::Bounded` to be specified in helper attributes, enabling the generation of `TryFrom` and `Into` implementations for types with restricted bit ranges as required by the nova-core [1]. - Add compile-time overflow assertion to ensure that enum discriminants fit within the types being converted to or from, preventing silent overflows. Note: 1015+ insertions are purely from doctests. Most of them are kept private to keep the public API documentation clean and simple for users. This might not be the usual way of doing things, but for now I don't think I have a better option. Feedback and suggestions are always appreciated. [1] https://lore.kernel.org/rust-for-linux/DDHU4LL4GGIY.16OJMIL7ZK58P@nvidia.com/ Best regards, Jesung --- Changes in v3: - Use the vendored `syn` and `quote` crates. - Support `kernel::num::Bounded`. - Add compile-time overflow assertion. - Add a comment about `#[repr(C)]` enums. - Drop Tested-by and Reviewed-by tags, as the code structure has changed substantially. (Thanks for the previous reviews and testing!) - Link to v2: https://lore.kernel.org/rust-for-linux/cover.1755235180.git.y.j3ms.n@gmail.com/ Changes in v2 (no functional changes): - Split the patch "rust: macros: extend custom `quote!()` macro" into two separate patches. - Remove unnecessary spaces between tags. - Use a consistent commit subject prefix: "rust: macros:". - Add Tested-by tags. - Link to v1: https://lore.kernel.org/rust-for-linux/cover.1754228164.git.y.j3ms.n@gmail.com/ --- Jesung Yang (4): rust: macros: add derive macro for `Into` rust: macros: add derive macro for `TryFrom` rust: macros: add private doctests for `Into` derive macro rust: macros: add private doctests for `TryFrom` derive macro rust/macros/convert.rs | 1546 ++++++++++++++++++++++++++++++++++++++++ rust/macros/lib.rs | 319 +++++++++ 2 files changed, 1865 insertions(+) create mode 100644 rust/macros/convert.rs base-commit: 9448598b22c50c8a5bb77a9103e2d49f134c9578 -- 2.47.3