Skip to content

Commit 445702d

Browse files
authored
Rollup merge of rust-lang#99026 - anall:buffix/clippy-9131, r=xFrednet
Add test for and fix rust-lang/rust-clippy#9131 This lint seems to have been broken by rust-lang#98446 -- but of course, there was no clippy test for this case at the time. `expr.span.ctxt().outer_expn_data()` now has `MacroKind::Derive` instead of `MacroKind::Attr` for something like: ``` #[derive(Clone, Debug)] pub struct UnderscoreInStruct { _foo: u32, } ``` --- changelog: none closes: rust-lang/rust-clippy#9131
2 parents e58c2d4 + 98b8419 commit 445702d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/tools/clippy/clippy_lints/src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
301301
use rustc_span::hygiene::MacroKind;
302302
if expr.span.from_expansion() {
303303
let data = expr.span.ctxt().outer_expn_data();
304-
matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _))
304+
matches!(data.kind, ExpnKind::Macro(MacroKind::Attr|MacroKind::Derive, _))
305305
} else {
306306
false
307307
}

src/tools/clippy/tests/ui/used_underscore_binding.rs

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ fn in_struct_field() {
4444
s._underscore_field += 1;
4545
}
4646

47+
/// Tests that we do not lint if the struct field is used in code created with derive.
48+
#[derive(Clone, Debug)]
49+
pub struct UnderscoreInStruct {
50+
_foo: u32,
51+
}
52+
4753
/// Tests that we do not lint if the underscore is not a prefix
4854
fn non_prefix_underscore(some_foo: u32) -> u32 {
4955
some_foo + 1

src/tools/clippy/tests/ui/used_underscore_binding.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LL | s._underscore_field += 1;
3131
| ^^^^^^^^^^^^^^^^^^^
3232

3333
error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
34-
--> $DIR/used_underscore_binding.rs:99:16
34+
--> $DIR/used_underscore_binding.rs:105:16
3535
|
3636
LL | uses_i(_i);
3737
| ^^

0 commit comments

Comments
 (0)