init: allow nonstandard_style for generated accessor/value#127
init: allow nonstandard_style for generated accessor/value#127Mirko-A wants to merge 3 commits intoRust-for-Linux:mainfrom
nonstandard_style for generated accessor/value#127Conversation
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: Rust-for-Linux#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>
|
Tested with the following changes: diff --git a/examples/big_struct_in_place.rs b/examples/big_struct_in_place.rs
index 80f89b5..5525cae 100644
--- a/examples/big_struct_in_place.rs
+++ b/examples/big_struct_in_place.rs
@@ -13,8 +13,8 @@ pub struct BigStruct {
a: u64,
b: u64,
c: u64,
- d: u64,
- managed_buf: ManagedBuf,
+ NONSTANDARD_D: u64,
+ MANAGED_BUF: ManagedBuf,
}
#[derive(Debug)]
@@ -37,8 +37,8 @@ fn main() {
a: 7,
b: 186,
c: 7789,
- d: 34,
- managed_buf <- ManagedBuf::new(),
+ NONSTANDARD_D: 34,
+ MANAGED_BUF <- ManagedBuf::new(),
}))
.unwrap();
println!("{}", core::mem::size_of_val(&*buf));Output before the patch: $ cargo run --example big_struct_in_place
[...]
error: structure field `NONSTANDARD_D` should have a snake case name
--> examples/big_struct_in_place.rs:16:5
|
16 | NONSTANDARD_D: u64,
| ^^^^^^^^^^^^^ help: convert the identifier to snake case: `nonstandard_d`
|
= note: `-D non-snake-case` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(non_snake_case)]`
error: structure field `MANAGED_BUF` should have a snake case name
--> examples/big_struct_in_place.rs:17:5
|
17 | MANAGED_BUF: ManagedBuf,
| ^^^^^^^^^^^ help: convert the identifier to snake case: `managed_buf`
error: variable `NONSTANDARD_D` should have a snake case name
--> examples/big_struct_in_place.rs:40:28
|
40 | NONSTANDARD_D: 34,
| ^^ help: convert the identifier to snake case: `nonstandard_d`
error: variable `NONSTANDARD_D` should have a snake case name
--> examples/big_struct_in_place.rs:40:13
|
40 | NONSTANDARD_D: 34,
| ^^^^^^^^^^^^^ help: convert the identifier to snake case: `nonstandard_d`
error: variable `MANAGED_BUF` should have a snake case name
--> examples/big_struct_in_place.rs:41:13
|
41 | MANAGED_BUF <- ManagedBuf::new(),
| ^^^^^^^^^^^ help: convert the identifier to snake case: `managed_buf`
error: could not compile `pin-init` (example "big_struct_in_place") due to 5 previous errorsOutput after the patch: $ cargo run --example big_struct_in_place
[...]
error: structure field `NONSTANDARD_D` should have a snake case name
--> examples/big_struct_in_place.rs:16:5
|
16 | NONSTANDARD_D: u64,
| ^^^^^^^^^^^^^ help: convert the identifier to snake case: `nonstandard_d`
|
= note: `-D non-snake-case` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(non_snake_case)]`
error: structure field `MANAGED_BUF` should have a snake case name
--> examples/big_struct_in_place.rs:17:5
|
17 | MANAGED_BUF: ManagedBuf,
| ^^^^^^^^^^^ help: convert the identifier to snake case: `managed_buf`
error: could not compile `pin-init` (example "big_struct_in_place") due to 2 previous errorsI am still quite new to the process of contributing to Rust-For-Linux. Please let me know if I've made any mistakes or if I've missed something. |
|
Please add a test for this |
|
Does something like this look okay? |
|
I think what you want is not a compile_fail test, but rather than the code (with |
e90104e to
2d194be
Compare
|
Right, that sounds like a better approach. I've amended the existing test commit to keep the branch clean, hopefully that's okay: 2d194be
I put the test under the existing |
|
Two more things:
|
|
|
e65a45e to
c7a56c5
Compare
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 <adzicmirko97@gmail.com>
Signed-off-by: Mirko Adzic <adzicmirko97@gmail.com>
c7a56c5 to
f7e5864
Compare
| used for structs with non-snake-case field names. Warnings are still reported on the | ||
| struct definition, as expected. |
There was a problem hiding this comment.
| 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. |
| struct Bar { | ||
| Non_Standard_C: usize, | ||
| } | ||
|
|
There was a problem hiding this comment.
Can you add a test case with pin_init!() macro and a struct with #[pin_data]?
Allows
nonstandard_stylelint on accessors/values generated as local variables ininit!.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]")