2 // aux-build:proc_macro_derive.rs
4 #![feature(rustc_private)]
6 #![allow(clippy::blacklisted_name, clippy::eq_op)]
7 #![warn(clippy::used_underscore_binding)]
10 extern crate proc_macro_derive;
12 // This should not trigger the lint. There's underscore binding inside the external derive that
13 // would trigger the `used_underscore_binding` lint.
14 #[derive(DeriveSomething)]
17 macro_rules! test_macro {
24 /// Tests that we lint if we use a binding with a single leading underscore
25 fn prefix_underscore(_foo: u32) -> u32 {
29 /// Tests that we lint if we use a `_`-variable defined outside within a macro expansion
30 fn in_macro_or_desugar(_foo: u32) {
32 assert_eq!(_foo, _foo);
37 // Struct for testing use of fields prefixed with an underscore
38 struct StructFieldTest {
39 _underscore_field: u32,
42 /// Tests that we lint the use of a struct field which is prefixed with an underscore
43 fn in_struct_field() {
44 let mut s = StructFieldTest { _underscore_field: 0 };
45 s._underscore_field += 1;
48 /// Tests that we do not lint if the underscore is not a prefix
49 fn non_prefix_underscore(some_foo: u32) -> u32 {
53 /// Tests that we do not lint if we do not use the binding (simple case)
54 fn unused_underscore_simple(_foo: u32) -> u32 {
58 /// Tests that we do not lint if we do not use the binding (complex case). This checks for
59 /// compatibility with the built-in `unused_variables` lint.
60 fn unused_underscore_complex(mut _foo: u32) -> u32 {
66 /// Test that we do not lint for multiple underscores
67 fn multiple_underscores(__foo: u32) -> u32 {
71 // Non-variable bindings with preceding underscore
79 /// Tests that we do not lint for non-variable bindings
83 let _e = match _EnumTest::_Value(_StructTest) {
84 _EnumTest::_Empty => 0,
85 _EnumTest::_Value(_st) => 1,
91 // Tests that we do not lint if the binding comes from await desugaring,
92 // but we do lint the awaited expression. See issue 5360.
93 async fn await_desugaring() {
108 // tests of unused_underscore lint
109 let _ = prefix_underscore(foo);
110 in_macro_or_desugar(foo);
112 // possible false positives
113 let _ = non_prefix_underscore(foo);
114 let _ = unused_underscore_simple(foo);
115 let _ = unused_underscore_complex(foo);
116 let _ = multiple_underscores(foo);