Skip to content

Commit 65d88c7

Browse files
committed
Auto merge of #4011 - phansch:add_test_for_derive_expansion, r=flip1995
Add test for derives for used_underscore_binding lint This closes #852 as I can't reproduce the original issue anymore. changelog: none
2 parents 54e80c7 + 60a1759 commit 65d88c7

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

tests/ui/auxiliary/proc_macro_derive.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ use proc_macro::{quote, TokenStream};
99

1010
#[proc_macro_derive(DeriveSomething)]
1111
pub fn derive(_: TokenStream) -> TokenStream {
12+
// Shound not trigger `used_underscore_binding`
13+
let _inside_derive = 1;
14+
assert_eq!(_inside_derive, _inside_derive);
15+
1216
let output = quote! {
17+
// Should not trigger `useless_attribute`
1318
#[allow(dead_code)]
1419
extern crate clippy_lints;
1520
};

tests/ui/used_underscore_binding.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
// aux-build:proc_macro_derive.rs
2+
13
#![warn(clippy::all)]
24
#![allow(clippy::blacklisted_name)]
35
#![warn(clippy::used_underscore_binding)]
46

7+
#[macro_use]
8+
extern crate proc_macro_derive;
9+
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)]
13+
struct Baz;
14+
515
macro_rules! test_macro {
616
() => {{
717
let _foo = 42;
@@ -51,7 +61,7 @@ fn unused_underscore_complex(mut _foo: u32) -> u32 {
5161
1
5262
}
5363

54-
///Test that we do not lint for multiple underscores
64+
/// Test that we do not lint for multiple underscores
5565
fn multiple_underscores(__foo: u32) -> u32 {
5666
__foo + 1
5767
}

tests/ui/used_underscore_binding.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
2-
--> $DIR/used_underscore_binding.rs:14:5
2+
--> $DIR/used_underscore_binding.rs:24:5
33
|
44
LL | _foo + 1
55
| ^^^^
66
|
77
= note: `-D clippy::used-underscore-binding` implied by `-D warnings`
88

99
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
10-
--> $DIR/used_underscore_binding.rs:19:20
10+
--> $DIR/used_underscore_binding.rs:29:20
1111
|
1212
LL | println!("{}", _foo);
1313
| ^^^^
1414

1515
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
16-
--> $DIR/used_underscore_binding.rs:20:16
16+
--> $DIR/used_underscore_binding.rs:30:16
1717
|
1818
LL | assert_eq!(_foo, _foo);
1919
| ^^^^
2020

2121
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
22-
--> $DIR/used_underscore_binding.rs:20:22
22+
--> $DIR/used_underscore_binding.rs:30:22
2323
|
2424
LL | assert_eq!(_foo, _foo);
2525
| ^^^^
2626

2727
error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
28-
--> $DIR/used_underscore_binding.rs:33:5
28+
--> $DIR/used_underscore_binding.rs:43:5
2929
|
3030
LL | s._underscore_field += 1;
3131
| ^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)