Skip to content

Commit 4e8592e

Browse files
committed
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 <gary@garyguo.net> Link: #125 Closes: https://lore.kernel.org/rust-for-linux/DGTBJBIVFZ2K.2F1ZEFGY0G7NK@garyguo.net/ Fixes: f1b0c3c ("internal: init: remove #[disable_initialized_field_access]") Signed-off-by: Mirko Adzic <adzicmirko97@gmail.com>
1 parent 0ce5e88 commit 4e8592e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

internal/src/init.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ 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 `nonstandard_style` since the same warning is going to be reported for
250+
// the struct field.
251+
#[allow(nonstandard_style)]
252+
let #value_ident = #value;
253+
}
249254
});
250255
// Again span for better diagnostics
251256
let write = quote_spanned!(ident.span()=> ::core::ptr::write);
@@ -273,7 +278,9 @@ fn init_fields(
273278
unsafe { #write(&raw mut (*#slot).#ident, #value_ident) };
274279
}
275280
#(#cfgs)*
276-
#[allow(unused_variables)]
281+
// Allow `nonstandard_style` since the same warning is going to be reported for
282+
// the struct field.
283+
#[allow(unused_variables, nonstandard_style)]
277284
let #ident = #accessor;
278285
}
279286
}
@@ -325,7 +332,9 @@ fn init_fields(
325332
#value_init
326333
}
327334
#(#cfgs)*
328-
#[allow(unused_variables)]
335+
// Allow `nonstandard_style` since the same warning is going to be reported for
336+
// the struct field.
337+
#[allow(unused_variables, nonstandard_style)]
329338
let #ident = #accessor;
330339
}
331340
}

0 commit comments

Comments
 (0)