From 4e8592e640ff5145560098cd36ea0fc846fd258f Mon Sep 17 00:00:00 2001 From: Mirko Adzic Date: Wed, 1 Apr 2026 20:04:19 +0200 Subject: [PATCH 1/6] init: allow `nonstandard_style` for generated accessor/value Allows `nonstandard_style` lint on accessors/values generated as local variables in `init!`. Since the same warning will be reported by the compiler on the struct field, having the extra warning for the generated accessor/value is unnecessary and confusing. Reported-by: Gary Guo Link: https://github.com/Rust-for-Linux/pin-init/issues/125 Closes: https://lore.kernel.org/rust-for-linux/DGTBJBIVFZ2K.2F1ZEFGY0G7NK@garyguo.net/ Fixes: f1b0c3c79a8d ("internal: init: remove #[disable_initialized_field_access]") Signed-off-by: Mirko Adzic --- internal/src/init.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/src/init.rs b/internal/src/init.rs index daa3f1c..99101a4 100644 --- a/internal/src/init.rs +++ b/internal/src/init.rs @@ -245,7 +245,12 @@ fn init_fields( // Setting the span of `value_ident` to `value`'s span improves error messages // when the type of `value` is wrong. value_ident.set_span(value.span()); - quote!(let #value_ident = #value;) + quote! { + // Allow `nonstandard_style` since the same warning is going to be reported for + // the struct field. + #[allow(nonstandard_style)] + let #value_ident = #value; + } }); // Again span for better diagnostics let write = quote_spanned!(ident.span()=> ::core::ptr::write); @@ -273,7 +278,9 @@ fn init_fields( unsafe { #write(&raw mut (*#slot).#ident, #value_ident) }; } #(#cfgs)* - #[allow(unused_variables)] + // Allow `nonstandard_style` since the same warning is going to be reported for + // the struct field. + #[allow(unused_variables, nonstandard_style)] let #ident = #accessor; } } @@ -325,7 +332,9 @@ fn init_fields( #value_init } #(#cfgs)* - #[allow(unused_variables)] + // Allow `nonstandard_style` since the same warning is going to be reported for + // the struct field. + #[allow(unused_variables, nonstandard_style)] let #ident = #accessor; } } From 5be2d62d6ad9934269454b7479f469a05b697c70 Mon Sep 17 00:00:00 2001 From: Mirko Adzic Date: Wed, 1 Apr 2026 21:38:02 +0200 Subject: [PATCH 2/6] test: add `nonstandard_style` lint test Adds a test to make sure that no excess warnings are emitted when dealing with non-standard field names in `init!`. Signed-off-by: Mirko Adzic --- tests/nonstandard_style.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/nonstandard_style.rs diff --git a/tests/nonstandard_style.rs b/tests/nonstandard_style.rs new file mode 100644 index 0000000..07ad4df --- /dev/null +++ b/tests/nonstandard_style.rs @@ -0,0 +1,31 @@ +//! Tests that no extra warnings are emitted for non-standard style fields when using `init!`. +//! +//! See: https://github.com/Rust-for-Linux/pin-init/issues/125 + +// Should be implied by crate lint settings, but just to be sure: +#![deny(nonstandard_style)] +#![allow(dead_code)] +#![cfg_attr(USE_RUSTC_FEATURES, feature(lint_reasons))] +#![cfg_attr(USE_RUSTC_FEATURES, feature(raw_ref_op))] + +use pin_init::*; + +#[allow(nonstandard_style)] +struct Foo { + NON_STANDARD_A: usize, + nonStandardB: Bar, +} + +#[allow(non_snake_case)] +struct Bar { + Non_Standard_C: usize, +} + +impl Foo { + fn new() -> impl Init { + init!(Self { + NON_STANDARD_A: 42, + nonStandardB <- init!(Bar { Non_Standard_C: 42 }), + }) + } +} From d4e1179c542a283a141cc34b8383177c9c5f7110 Mon Sep 17 00:00:00 2001 From: Mirko Adzic Date: Sat, 4 Apr 2026 17:17:56 +0200 Subject: [PATCH 3/6] update changelog Signed-off-by: Mirko Adzic --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f84cd..22584fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Corrected `T: Sized` bounds to `T: ?Sized` in the generated `PinnedDrop` check by `#[pin_data]`. +- `init!` no longer produces `nonstandard_style` group warnings at the call site, when + used for structs with non-snake-case field names. Warnings on the struct definition + are unaffected. ## [0.0.10] - 2025-08-19 From 6699b734b4300ab3c85c8749fd52da2a0e044e4d Mon Sep 17 00:00:00 2001 From: Mirko Adzic Date: Wed, 8 Apr 2026 12:11:05 +0200 Subject: [PATCH 4/6] pin_init: allow `nonstandard_style` for generated identifiers Allows `nonstandard_style` lint on locally generated identifiers in `pin_init!`. Since the same warning will be reported by the compiler on the struct definition, having the extra warning emitted at the macro call site is unnecessary and confusing. Suggested-by: Gary Guo Link: https://github.com/Rust-for-Linux/pin-init/issues/125 Signed-off-by: Mirko Adzic --- internal/src/pin_data.rs | 12 ++++++++++-- tests/ui/expand/many_generics.expanded.rs | 7 +++++-- tests/ui/expand/pin-data.expanded.rs | 6 ++++-- tests/ui/expand/pinned_drop.expanded.rs | 6 ++++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/internal/src/pin_data.rs b/internal/src/pin_data.rs index 7d87123..5e630ef 100644 --- a/internal/src/pin_data.rs +++ b/internal/src/pin_data.rs @@ -164,7 +164,10 @@ fn generate_unpin_impl( quote! { // This struct will be used for the unpin analysis. It is needed, because only structurally // pinned fields are relevant whether the struct should implement `Unpin`. - #[allow(dead_code)] // The fields below are never used. + #[allow( + dead_code, // The fields below are never used. + nonstandard_style // The warning will be emitted on the struct definition. + )] struct __Unpin #generics_with_pin_lt #where_token #predicates @@ -302,7 +305,9 @@ fn generate_projections( let docs = format!(" Pin-projections of [`{ident}`]"); quote! { #[doc = #docs] - #[allow(dead_code)] + // Allow `nonstandard_style` since the same warning will be emitted on + // the struct definition. + #[allow(dead_code, nonstandard_style)] #[doc(hidden)] #vis struct #projection #generics_with_pin_lt { #(#fields_decl)* @@ -395,6 +400,9 @@ fn generate_the_pin_data( /// to deallocate. #pin_safety #(#attrs)* + // Allow `nonstandard_style` since the same warning will be emitted on + // the struct definition. + #[allow(nonstandard_style)] #vis unsafe fn #ident( self, slot: *mut #ty, diff --git a/tests/ui/expand/many_generics.expanded.rs b/tests/ui/expand/many_generics.expanded.rs index 35f9910..c5198f3 100644 --- a/tests/ui/expand/many_generics.expanded.rs +++ b/tests/ui/expand/many_generics.expanded.rs @@ -13,7 +13,7 @@ where _pin: PhantomPinned, } /// Pin-projections of [`Foo`] -#[allow(dead_code)] +#[allow(dead_code, nonstandard_style)] #[doc(hidden)] struct FooProjection< '__pin, @@ -92,6 +92,7 @@ const _: () = { /// - `slot` is a valid pointer to uninitialized memory. /// - the caller does not touch `slot` when `Err` is returned, they are only permitted /// to deallocate. + #[allow(nonstandard_style)] unsafe fn array( self, slot: *mut [u8; 1024 * 1024], @@ -113,6 +114,7 @@ const _: () = { /// - `slot` is a valid pointer to uninitialized memory. /// - the caller does not touch `slot` when `Err` is returned, they are only permitted /// to deallocate. + #[allow(nonstandard_style)] unsafe fn r( self, slot: *mut &'b mut [&'a mut T; SIZE], @@ -135,6 +137,7 @@ const _: () = { /// - the caller does not touch `slot` when `Err` is returned, they are only permitted /// to deallocate. /// - `slot` will not move until it is dropped, i.e. it will be pinned. + #[allow(nonstandard_style)] unsafe fn _pin( self, slot: *mut PhantomPinned, @@ -179,7 +182,7 @@ const _: () = { { type Datee = Foo<'a, 'b, T, SIZE>; } - #[allow(dead_code)] + #[allow(dead_code, nonstandard_style)] struct __Unpin<'__pin, 'a, 'b: 'a, T: Bar<'b> + ?Sized + 'a, const SIZE: usize = 0> where T: Bar<'a, 1>, diff --git a/tests/ui/expand/pin-data.expanded.rs b/tests/ui/expand/pin-data.expanded.rs index fb59d86..1ac036a 100644 --- a/tests/ui/expand/pin-data.expanded.rs +++ b/tests/ui/expand/pin-data.expanded.rs @@ -5,7 +5,7 @@ struct Foo { _pin: PhantomPinned, } /// Pin-projections of [`Foo`] -#[allow(dead_code)] +#[allow(dead_code, nonstandard_style)] #[doc(hidden)] struct FooProjection<'__pin> { array: &'__pin mut [u8; 1024 * 1024], @@ -51,6 +51,7 @@ const _: () = { /// - `slot` is a valid pointer to uninitialized memory. /// - the caller does not touch `slot` when `Err` is returned, they are only permitted /// to deallocate. + #[allow(nonstandard_style)] unsafe fn array( self, slot: *mut [u8; 1024 * 1024], @@ -73,6 +74,7 @@ const _: () = { /// - the caller does not touch `slot` when `Err` is returned, they are only permitted /// to deallocate. /// - `slot` will not move until it is dropped, i.e. it will be pinned. + #[allow(nonstandard_style)] unsafe fn _pin( self, slot: *mut PhantomPinned, @@ -101,7 +103,7 @@ const _: () = { unsafe impl ::pin_init::__internal::PinData for __ThePinData { type Datee = Foo; } - #[allow(dead_code)] + #[allow(dead_code, nonstandard_style)] struct __Unpin<'__pin> { __phantom_pin: ::core::marker::PhantomData &'__pin ()>, __phantom: ::core::marker::PhantomData Foo>, diff --git a/tests/ui/expand/pinned_drop.expanded.rs b/tests/ui/expand/pinned_drop.expanded.rs index 5e0f125..287fd04 100644 --- a/tests/ui/expand/pinned_drop.expanded.rs +++ b/tests/ui/expand/pinned_drop.expanded.rs @@ -5,7 +5,7 @@ struct Foo { _pin: PhantomPinned, } /// Pin-projections of [`Foo`] -#[allow(dead_code)] +#[allow(dead_code, nonstandard_style)] #[doc(hidden)] struct FooProjection<'__pin> { array: &'__pin mut [u8; 1024 * 1024], @@ -51,6 +51,7 @@ const _: () = { /// - `slot` is a valid pointer to uninitialized memory. /// - the caller does not touch `slot` when `Err` is returned, they are only permitted /// to deallocate. + #[allow(nonstandard_style)] unsafe fn array( self, slot: *mut [u8; 1024 * 1024], @@ -73,6 +74,7 @@ const _: () = { /// - the caller does not touch `slot` when `Err` is returned, they are only permitted /// to deallocate. /// - `slot` will not move until it is dropped, i.e. it will be pinned. + #[allow(nonstandard_style)] unsafe fn _pin( self, slot: *mut PhantomPinned, @@ -101,7 +103,7 @@ const _: () = { unsafe impl ::pin_init::__internal::PinData for __ThePinData { type Datee = Foo; } - #[allow(dead_code)] + #[allow(dead_code, nonstandard_style)] struct __Unpin<'__pin> { __phantom_pin: ::core::marker::PhantomData &'__pin ()>, __phantom: ::core::marker::PhantomData Foo>, From 02ad57b7fea4e536ade2a898e9b9c640a462b4f8 Mon Sep 17 00:00:00 2001 From: Mirko Adzic Date: Wed, 8 Apr 2026 12:13:38 +0200 Subject: [PATCH 5/6] test: expand `nonstandard_style` lint test Expands the test to also cover usage of `pin_init!` (instead of only `init!`) on structs with non-standard style field names. Suggested-by: Gary Guo Signed-off-by: Mirko Adzic --- tests/nonstandard_style.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/nonstandard_style.rs b/tests/nonstandard_style.rs index 07ad4df..372ea20 100644 --- a/tests/nonstandard_style.rs +++ b/tests/nonstandard_style.rs @@ -1,4 +1,5 @@ -//! Tests that no extra warnings are emitted for non-standard style fields when using `init!`. +//! Tests that no extra warnings are emitted for non-standard style fields when using `init!` +//! or `pin_init!`. //! //! See: https://github.com/Rust-for-Linux/pin-init/issues/125 @@ -16,6 +17,7 @@ struct Foo { nonStandardB: Bar, } +// Make sure `allow(non_snake_case)` also works. #[allow(non_snake_case)] struct Bar { Non_Standard_C: usize, @@ -29,3 +31,20 @@ impl Foo { }) } } + +#[allow(nonstandard_style)] +#[pin_data] +struct Baz { + NON_STANDARD: usize, + #[pin] + nonStandardPin: usize, +} + +impl Baz { + fn new(a: impl PinInit) -> impl PinInit { + pin_init!(Self { + NON_STANDARD: 42, + nonStandardPin <- a, + }) + } +} From 7a0d2dafae8629c7fbe959383f8f33d392812f56 Mon Sep 17 00:00:00 2001 From: Mirko Adzic Date: Wed, 8 Apr 2026 12:17:35 +0200 Subject: [PATCH 6/6] update changelog Signed-off-by: Mirko Adzic --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22584fc..8a41413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,9 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Corrected `T: Sized` bounds to `T: ?Sized` in the generated `PinnedDrop` check by `#[pin_data]`. -- `init!` no longer produces `nonstandard_style` group warnings at the call site, when - used for structs with non-snake-case field names. Warnings on the struct definition - are unaffected. +- `init!` and `pin_init!` no longer produce `nonstandard_style` group warnings at the + call site when used for structs with non-snake-case field names. Warnings on the + struct definition are unaffected. ## [0.0.10] - 2025-08-19