Skip to content

Commit 0116ff1

Browse files
committed
test: add nonstandard_style lint test
Adds a test to make sure that no excess warnings are emitted by `#[pin_data]`, `init!` or `pin_init!` when dealing with non-standard field names. Signed-off-by: Mirko Adzic <adzicmirko97@gmail.com>
1 parent 971e64c commit 0116ff1

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tests/nonstandard_style.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//! Tests that no extra warnings are emitted for non-snake-case fields when using
2+
//! `#[pin_data]`, `init!` or `pin_init!`.
3+
//!
4+
//! See: https://github.com/Rust-for-Linux/pin-init/issues/125
5+
6+
#![deny(nonstandard_style)]
7+
#![allow(dead_code)]
8+
#![cfg_attr(USE_RUSTC_FEATURES, feature(lint_reasons))]
9+
#![cfg_attr(USE_RUSTC_FEATURES, feature(raw_ref_op))]
10+
11+
use pin_init::*;
12+
13+
#[allow(non_snake_case)]
14+
struct Foo {
15+
NON_STANDARD_A: usize,
16+
nonStandardB: Bar,
17+
}
18+
19+
#[allow(non_snake_case)]
20+
struct Bar {
21+
Non_Standard_C: usize,
22+
}
23+
24+
impl Foo {
25+
fn new() -> impl Init<Self> {
26+
init!(Self {
27+
NON_STANDARD_A: {
28+
#[expect(
29+
nonstandard_style,
30+
reason = "User code warnings should not be suppressed"
31+
)]
32+
(0..2).map(|NonStandardInUserCode| NonStandardInUserCode + 1).sum()
33+
},
34+
nonStandardB <- init!(Bar { Non_Standard_C: 42 }),
35+
})
36+
}
37+
}
38+
39+
// Non-camel-case struct name should not produce warnings.
40+
#[allow(nonstandard_style)]
41+
#[pin_data]
42+
struct non_standard_baz {
43+
NON_STANDARD: usize,
44+
#[pin]
45+
nonStandardPin: usize,
46+
}
47+
48+
impl non_standard_baz {
49+
fn new(a: impl PinInit<usize>) -> impl PinInit<Self> {
50+
pin_init!(Self {
51+
NON_STANDARD: {
52+
#[expect(
53+
nonstandard_style,
54+
reason = "User code warnings should not be suppressed"
55+
)]
56+
let NON_STANDARD_IN_USER_CODE = 41;
57+
NON_STANDARD_IN_USER_CODE + 1
58+
},
59+
nonStandardPin <- a,
60+
})
61+
}
62+
}

0 commit comments

Comments
 (0)