-
Notifications
You must be signed in to change notification settings - Fork 27
init: allow nonstandard_style for generated accessor/value
#127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4e8592e
5be2d62
d4e1179
6699b73
02ad57b
7a0d2da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, actually this can cause lints to be suppressed on Code like will be incorrectly suppressed? |
||
| 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; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //! 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 | ||
|
|
||
| // Should be implied by crate lint settings, but just to be sure: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sentence doesn't need to be here; this is an integral part of the test. |
||
| #![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, | ||
| } | ||
|
|
||
| // Make sure `allow(non_snake_case)` also works. | ||
| #[allow(non_snake_case)] | ||
| struct Bar { | ||
| Non_Standard_C: usize, | ||
| } | ||
|
|
||
nbdd0121 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| impl Foo { | ||
| fn new() -> impl Init<Self> { | ||
| init!(Self { | ||
| NON_STANDARD_A: 42, | ||
| nonStandardB <- init!(Bar { Non_Standard_C: 42 }), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[allow(nonstandard_style)] | ||
| #[pin_data] | ||
| struct Baz { | ||
| NON_STANDARD: usize, | ||
| #[pin] | ||
| nonStandardPin: usize, | ||
| } | ||
|
|
||
| impl Baz { | ||
| fn new(a: impl PinInit<usize>) -> impl PinInit<Self> { | ||
| pin_init!(Self { | ||
| NON_STANDARD: 42, | ||
| nonStandardPin <- a, | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, could you update code to use the specific lint, such as
non_snake_casefor suppression?Also, could you squash the changelog update into the same commit that update the code please.
You'd also probably want a line about
#[pin_data], to mention that lints can now be properly suppressed where it couldn't previously.