1 // aux-build:proc_macro_derive.rs
4 #![allow(clippy::blacklisted_name)]
5 #![warn(clippy::used_underscore_binding)]
8 extern crate proc_macro_derive;
10 // This should not trigger the lint. There's underscore binding inside the external derive that
11 // would trigger the `used_underscore_binding` lint.
12 #[derive(DeriveSomething)]
15 macro_rules! test_macro {
22 /// Tests that we lint if we use a binding with a single leading underscore
23 fn prefix_underscore(_foo: u32) -> u32 {
27 /// Tests that we lint if we use a `_`-variable defined outside within a macro expansion
28 fn in_macro(_foo: u32) {
30 assert_eq!(_foo, _foo);
35 // Struct for testing use of fields prefixed with an underscore
36 struct StructFieldTest {
37 _underscore_field: u32,
40 /// Tests that we lint the use of a struct field which is prefixed with an underscore
41 fn in_struct_field() {
42 let mut s = StructFieldTest { _underscore_field: 0 };
43 s._underscore_field += 1;
46 /// Tests that we do not lint if the underscore is not a prefix
47 fn non_prefix_underscore(some_foo: u32) -> u32 {
51 /// Tests that we do not lint if we do not use the binding (simple case)
52 fn unused_underscore_simple(_foo: u32) -> u32 {
56 /// Tests that we do not lint if we do not use the binding (complex case). This checks for
57 /// compatibility with the built-in `unused_variables` lint.
58 fn unused_underscore_complex(mut _foo: u32) -> u32 {
64 /// Test that we do not lint for multiple underscores
65 fn multiple_underscores(__foo: u32) -> u32 {
69 // Non-variable bindings with preceding underscore
77 /// Tests that we do not lint for non-variable bindings
81 let _e = match _EnumTest::_Value(_StructTest) {
82 _EnumTest::_Empty => 0,
83 _EnumTest::_Value(_st) => 1,
91 // tests of unused_underscore lint
92 let _ = prefix_underscore(foo);
95 // possible false positives
96 let _ = non_prefix_underscore(foo);
97 let _ = unused_underscore_simple(foo);
98 let _ = unused_underscore_complex(foo);
99 let _ = multiple_underscores(foo);