Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] rust: macros: Into derive fails on repr with nested arguments - [Low] rust: macros: Bounded validation incorrectly accepts bool --
commit f3bc2f572cd1e2c7a2b7b3fee89fc39e25420448 Author: Jesung Yang <[email protected]> rust: macros: add derive macro for Into This commit introduces a procedural macro Into to automatically derive the Into trait for unit-only enums. It generates From implementations based on the into or repr attributes, supporting primitive types and the Bounded type. It also generates compile-time assertions to ensure variant discriminants fit within the destination type. Link: https://lore.kernel.org/rust-for-linux/[email protected]/ [1] > diff --git a/rust/macros/convert.rs b/rust/macros/convert.rs > new file mode 100644 > index 0000000000000..6702c2e48c1fe > --- /dev/null > +++ b/rust/macros/convert.rs > @@ -0,0 +1,527 @@ [ ... ] > +fn parse_attrs( > + target: DeriveTarget, > + attrs: &[Attribute], > +) -> syn::Result<(Vec<Type>, bool, Option<Ident>)> { > + let helper = target.get_helper_name(); > + > + let mut is_repr_c = false; > + let mut repr_ty = None; > + let mut helper_tys = Vec::new(); > + for attr in attrs { > + if attr.path().is_ident("repr") { > + attr.parse_nested_meta(|meta| { > + let ident = meta.path.get_ident(); > + if let Some(i) = ident { > + if is_valid_primitive(i) { > + repr_ty = ident.cloned(); > + } else if i == "C" { > + is_repr_c = true; > + } > + } > + // Delegate `repr` attribute validation to rustc. > + Ok(()) [Severity: Low] Does this closure returning Ok(()) without consuming the inner tokens cause parsing to fail? For example, if a developer applies #[derive(Into)] to an enum with a #[repr(align(4))] attribute, the inner token 4 is not consumed. Will this cause the syn crate to return a parsing error and break the build? > + })?; > + } else if attr.path().is_ident(helper) { > + let args = attr.parse_args_with(Punctuated::<Type, > Token![,]>::parse_terminated)?; > + helper_tys.extend(args); > + } > + } > + > + Ok((helper_tys, is_repr_c, repr_ty)) > +} [ ... ] > +fn validate_bounded(path_segment: &PathSegment) -> syn::Result<ValidTy> { > + let PathSegment { ident, arguments } = path_segment; > + return match arguments { > + PathArguments::AngleBracketed(inner) if ident == Bounded::NAME => { > + let AngleBracketedGenericArguments { > + colon2_token, args, .. > + } = inner; [ ... ] > + let Some(base_ty_ident) = base_ty_lowered.path.get_ident() else { > + return Err(make_base_ty_err(base_ty)); > + }; > + > + if !is_valid_primitive(base_ty_ident) { [Severity: Low] Does this validation step incorrectly accept bool as a base type for Bounded? Because is_valid_primitive() returns true for bool, specifying Bounded<bool, 1> passes this check. Later in the code, emit_min() attempts to emit MIN and BITS properties: rust/macros/convert.rs:emit_min() { ... ::quote::quote! { #base_ty::MIN >> (#base_ty::BITS - #bits) } ... } Since bool::MIN and bool::BITS do not exist, will this generate invalid code that causes the build to fail? > + return Err(make_base_ty_err(base_ty)); > + } -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
