Skip to content

Commit 971e64c

Browse files
committed
internal: init: allow nonstandard_style warnings for generated code
Allows `nonstandard_style` lint on accessors/values generated as local variables by `init!`/`pin_init!`. Since the same warning will be reported by the compiler on the struct definition, having the extra warning for the generated accessor/value is unnecessary and confusing. Reported-by: Gary Guo <gary@garyguo.net> Link: #125 Closes: https://lore.kernel.org/rust-for-linux/DGTBJBIVFZ2K.2F1ZEFGY0G7NK@garyguo.net/ Fixes: db96c51 ("add references to previously initialized fields") Signed-off-by: Mirko Adzic <adzicmirko97@gmail.com>
1 parent c94a5c7 commit 971e64c

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4040
check by `#[pin_data]`.
4141
- `#[pin_data]` no longer produces additional `non_snake_case` warnings if field names
4242
are not of snake case. Standard field definition warnings are unaffected.
43+
- `init!` and `pin_init!` no longer produce `non_snake_case` warnings if field names
44+
are not of snake case. Warnings on the struct definition are unaffected.
4345

4446
## [0.0.10] - 2025-08-19
4547

internal/src/init.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,14 @@ fn init_fields(
245245
// Setting the span of `value_ident` to `value`'s span improves error messages
246246
// when the type of `value` is wrong.
247247
value_ident.set_span(value.span());
248-
quote!(let #value_ident = #value;)
248+
quote! {
249+
// Allow `non_snake_case` since the same warning is going to be reported for
250+
// the struct field. Evaluate `#value` first so that user code warnings are not
251+
// suppressed.
252+
let __value_tmp = #value;
253+
#[allow(non_snake_case)]
254+
let #value_ident = __value_tmp;
255+
}
249256
});
250257
// Again span for better diagnostics
251258
let write = quote_spanned!(ident.span()=> ::core::ptr::write);
@@ -273,7 +280,9 @@ fn init_fields(
273280
unsafe { #write(&raw mut (*#slot).#ident, #value_ident) };
274281
}
275282
#(#cfgs)*
276-
#[allow(unused_variables)]
283+
// Allow `non_snake_case` since the same warning is going to be reported for
284+
// the struct field.
285+
#[allow(unused_variables, non_snake_case)]
277286
let #ident = #accessor;
278287
}
279288
}
@@ -325,7 +334,9 @@ fn init_fields(
325334
#value_init
326335
}
327336
#(#cfgs)*
328-
#[allow(unused_variables)]
337+
// Allow `non_snake_case` since the same warning is going to be reported for
338+
// the struct field.
339+
#[allow(unused_variables, non_snake_case)]
329340
let #ident = #accessor;
330341
}
331342
}

0 commit comments

Comments
 (0)