1 #![feature(tool_lints)]
5 #![allow(clippy::blacklisted_name)]
6 #![warn(clippy::used_underscore_binding)]
8 macro_rules! test_macro {
15 /// Test that we lint if we use a binding with a single leading underscore
16 fn prefix_underscore(_foo: u32) -> u32 {
20 /// Test that we lint if we use a `_`-variable defined outside within a macro expansion
21 fn in_macro(_foo: u32) {
23 assert_eq!(_foo, _foo);
28 // Struct for testing use of fields prefixed with an underscore
29 struct StructFieldTest {
30 _underscore_field: u32,
33 /// Test that we lint the use of a struct field which is prefixed with an underscore
34 fn in_struct_field() {
35 let mut s = StructFieldTest { _underscore_field: 0 };
36 s._underscore_field += 1;
39 /// Test that we do not lint if the underscore is not a prefix
40 fn non_prefix_underscore(some_foo: u32) -> u32 {
44 /// Test that we do not lint if we do not use the binding (simple case)
45 fn unused_underscore_simple(_foo: u32) -> u32 {
49 /// Test that we do not lint if we do not use the binding (complex case). This checks for
50 /// compatibility with the built-in `unused_variables` lint.
51 fn unused_underscore_complex(mut _foo: u32) -> u32 {
57 ///Test that we do not lint for multiple underscores
58 fn multiple_underscores(__foo: u32) -> u32 {
62 // Non-variable bindings with preceding underscore
70 /// Test that we do not lint for non-variable bindings
74 let _e = match _EnumTest::_Value(_StructTest) {
75 _EnumTest::_Empty => 0,
76 _EnumTest::_Value(_st) => 1,
84 // tests of unused_underscore lint
85 let _ = prefix_underscore(foo);
88 // possible false positives
89 let _ = non_prefix_underscore(foo);
90 let _ = unused_underscore_simple(foo);
91 let _ = unused_underscore_complex(foo);
92 let _ = multiple_underscores(foo);