Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +42 to +43
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
used for structs with non-snake-case field names. Warnings are still reported on the
struct definition, as expected.
used for structs with non-snake-case field names. Warnings on the
struct definition are unaffected.


## [0.0.10] - 2025-08-19

Expand Down
15 changes: 12 additions & 3 deletions internal/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
31 changes: 31 additions & 0 deletions tests/nonstandard_style.rs
Original file line number Diff line number Diff line change
@@ -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,
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case with pin_init!() macro and a struct with #[pin_data]?

impl Foo {
fn new() -> impl Init<Self> {
init!(Self {
NON_STANDARD_A: 42,
nonStandardB <- init!(Bar { Non_Standard_C: 42 }),
})
}
}
Loading