From 4e8592e640ff5145560098cd36ea0fc846fd258f Mon Sep 17 00:00:00 2001 From: Mirko Adzic Date: Wed, 1 Apr 2026 20:04:19 +0200 Subject: [PATCH 1/3] 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/3] 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 f7e58642d4a64493c9faff6c2ff62f007440c4b4 Mon Sep 17 00:00:00 2001 From: Mirko Adzic Date: Sat, 4 Apr 2026 17:17:56 +0200 Subject: [PATCH 3/3] 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..442e37f 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 are still reported on the + struct definition, as expected. ## [0.0.10] - 2025-08-19