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: <DFMQSS27GS7G.1QA2Q44B7UAT0@garyguo.net>
Date: Mon, 12 Jan 2026 16:14:09 +0000
From: "Gary Guo" <gary@...yguo.net>
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: Re: [PATCH v2 04/15] rust: pin-init: internal: add utility API for
 syn error handling

On Sun Jan 11, 2026 at 12:25 PM GMT, Benno Lossin wrote:
> 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>);

I don't think it's a good idea to call a type `Error` when it could just be no
error.

I think what I propose in https://lore.kernel.org/all/DFK7ITVQ97RL.2SZ2ANDIQ39H3@garyguo.net
is better than what's implemented here.

Best,
Gary

> +
> +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);
> +        }
> +    }
> +}


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ