1 // aux-build:proc_macro_derive.rs
3 #![feature(rustc_private)]
5 #![allow(clippy::blacklisted_name, clippy::eq_op)]
6 #![warn(clippy::used_underscore_binding)]
9 extern crate proc_macro_derive;
11 // This should not trigger the lint. There's underscore binding inside the external derive that
12 // would trigger the `used_underscore_binding` lint.
13 #[derive(DeriveSomething)]
16 macro_rules! test_macro {
23 /// Tests that we lint if we use a binding with a single leading underscore
24 fn prefix_underscore(_foo: u32) -> u32 {
28 /// Tests that we lint if we use a `_`-variable defined outside within a macro expansion
29 fn in_macro_or_desugar(_foo: u32) {
31 assert_eq!(_foo, _foo);
36 // Struct for testing use of fields prefixed with an underscore
37 struct StructFieldTest {
38 _underscore_field: u32,
41 /// Tests that we lint the use of a struct field which is prefixed with an underscore
42 fn in_struct_field() {
43 let mut s = StructFieldTest { _underscore_field: 0 };
44 s._underscore_field += 1;
47 /// Tests that we do not lint if the underscore is not a prefix
48 fn non_prefix_underscore(some_foo: u32) -> u32 {
52 /// Tests that we do not lint if we do not use the binding (simple case)
53 fn unused_underscore_simple(_foo: u32) -> u32 {
57 /// Tests that we do not lint if we do not use the binding (complex case). This checks for
58 /// compatibility with the built-in `unused_variables` lint.
59 fn unused_underscore_complex(mut _foo: u32) -> u32 {
65 /// Test that we do not lint for multiple underscores
66 fn multiple_underscores(__foo: u32) -> u32 {
70 // Non-variable bindings with preceding underscore
78 /// Tests that we do not lint for non-variable bindings
82 let _e = match _EnumTest::_Value(_StructTest) {
83 _EnumTest::_Empty => 0,
84 _EnumTest::_Value(_st) => 1,
90 // Tests that we do not lint if the binding comes from await desugaring,
91 // but we do lint the awaited expression. See issue 5360.
92 async fn await_desugaring() {
107 // tests of unused_underscore lint
108 let _ = prefix_underscore(foo);
109 in_macro_or_desugar(foo);
111 // possible false positives
112 let _ = non_prefix_underscore(foo);
113 let _ = unused_underscore_simple(foo);
114 let _ = unused_underscore_complex(foo);
115 let _ = multiple_underscores(foo);