lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260111122554.2662175-5-lossin@kernel.org>
Date: Sun, 11 Jan 2026 13:25:02 +0100
From: Benno Lossin <lossin@...nel.org>
To: Benno Lossin <lossin@...nel.org>,
	Gary Guo <gary@...yguo.net>,
	Miguel Ojeda <ojeda@...nel.org>,
	Boqun Feng <boqun.feng@...il.com>,
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,
	Andreas Hindborg <a.hindborg@...nel.org>,
	Alice Ryhl <aliceryhl@...gle.com>,
	Trevor Gross <tmgross@...ch.edu>,
	Danilo Krummrich <dakr@...nel.org>,
	Fiona Behrens <me@...enk.dev>
Cc: rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH v2 04/15] rust: pin-init: internal: add utility API for syn error handling

Add a function to turn a `syn::Result<TokenStream>` into a
`TokenStream`, either containing the error or the normal stream.

Add a nullable custom error type wrapping `syn::Error`.

Signed-off-by: Benno Lossin <lossin@...nel.org>
---
Changes in v2: added this patch
---
 rust/pin-init/internal/src/lib.rs | 44 +++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/rust/pin-init/internal/src/lib.rs b/rust/pin-init/internal/src/lib.rs
index 4c4dc639ce82..21f5e33486ce 100644
--- a/rust/pin-init/internal/src/lib.rs
+++ b/rust/pin-init/internal/src/lib.rs
@@ -36,3 +36,47 @@ pub fn derive_zeroable(input: TokenStream) -> TokenStream {
 pub fn maybe_derive_zeroable(input: TokenStream) -> TokenStream {
     zeroable::maybe_derive(input.into()).into()
 }
+
+#[expect(dead_code)]
+fn ok_or_compile_error(res: syn::Result<proc_macro2::TokenStream>) -> TokenStream {
+    match res {
+        Ok(stream) => stream,
+        Err(error) => error.into_compile_error(),
+    }
+    .into()
+}
+
+pub(crate) struct Error(Option<syn::Error>);
+
+impl From<syn::Error> for Error {
+    fn from(value: syn::Error) -> Self {
+        Self(Some(value))
+    }
+}
+
+impl Error {
+    #[expect(dead_code)]
+    pub(crate) fn none() -> Self {
+        Self(None)
+    }
+
+    #[expect(dead_code)]
+    pub(crate) fn combine(&mut self, error: impl Into<Self>) {
+        let error = error.into();
+        if let Some(this) = self.0.as_mut() {
+            if let Some(error) = error.0 {
+                this.combine(error);
+            }
+        } else {
+            self.0 = error.0;
+        }
+    }
+}
+
+impl quote::ToTokens for Error {
+    fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
+        if let Some(error) = self.0.as_ref() {
+            quote::ToTokens::to_tokens(&error.to_compile_error(), tokens);
+        }
+    }
+}
-- 
2.52.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ