Add test for struct fields
This commit is contained in:
parent
98d21f9fc5
commit
bd82c082cb
@ -12,6 +12,17 @@ fn in_macro(_foo: u32) {
|
||||
println!("{}", _foo); //~ ERROR used binding which is prefixed with an underscore
|
||||
}
|
||||
|
||||
// Struct for testing use of fields prefixed with an underscore
|
||||
struct StructFieldTest {
|
||||
_underscore_field: u32,
|
||||
}
|
||||
|
||||
/// Test that we lint the use of a struct field which is prefixed with an underscore
|
||||
fn in_struct_field() {
|
||||
let mut s = StructFieldTest { _underscore_field: 0 };
|
||||
s._underscore_field += 1; //~ Error used binding which is prefixed with an underscore
|
||||
}
|
||||
|
||||
/// Test that we do not lint if the underscore is not a prefix
|
||||
fn non_prefix_underscore(some_foo: u32) -> u32 {
|
||||
some_foo + 1
|
||||
@ -22,7 +33,6 @@ fn unused_underscore_simple(_foo: u32) -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
#[deny(unused_variables)]
|
||||
/// Test that we do not lint if we do not use the binding (complex case). This checks for
|
||||
/// compatibility with the built-in `unused_variables` lint.
|
||||
fn unused_underscore_complex(mut _foo: u32) -> u32 {
|
||||
@ -61,6 +71,7 @@ fn main() {
|
||||
// tests of unused_underscore lint
|
||||
let _ = prefix_underscore(foo);
|
||||
in_macro(foo);
|
||||
in_struct_field();
|
||||
// possible false positives
|
||||
let _ = non_prefix_underscore(foo);
|
||||
let _ = unused_underscore_simple(foo);
|
||||
|
Loading…
x
Reference in New Issue
Block a user