about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-07-08 08:00:41 +0200
committerGitHub <noreply@github.com>2022-07-08 08:00:41 +0200
commit445702d0cb4c47b1c95c0756c0d189ff539ca7bb (patch)
tree202b412781a793d655e75b9c24d215aa2034fe39
parente58c2d4f52b6dfcd7095c4f12a7ef8879d282189 (diff)
parent98b84195a217f53659d8f88ff9427ac7e463ccfb (diff)
downloadrust-445702d0cb4c47b1c95c0756c0d189ff539ca7bb.tar.gz
rust-445702d0cb4c47b1c95c0756c0d189ff539ca7bb.zip
Rollup merge of #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 #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: https://github.com/rust-lang/rust-clippy/issues/9131
-rw-r--r--src/tools/clippy/clippy_lints/src/misc.rs2
-rw-r--r--src/tools/clippy/tests/ui/used_underscore_binding.rs6
-rw-r--r--src/tools/clippy/tests/ui/used_underscore_binding.stderr2
3 files changed, 8 insertions, 2 deletions
diff --git a/src/tools/clippy/clippy_lints/src/misc.rs b/src/tools/clippy/clippy_lints/src/misc.rs
index df2430ced6b..be7df08d89f 100644
--- a/src/tools/clippy/clippy_lints/src/misc.rs
+++ b/src/tools/clippy/clippy_lints/src/misc.rs
@@ -301,7 +301,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
     use rustc_span::hygiene::MacroKind;
     if expr.span.from_expansion() {
         let data = expr.span.ctxt().outer_expn_data();
-        matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _))
+        matches!(data.kind, ExpnKind::Macro(MacroKind::Attr|MacroKind::Derive, _))
     } else {
         false
     }
diff --git a/src/tools/clippy/tests/ui/used_underscore_binding.rs b/src/tools/clippy/tests/ui/used_underscore_binding.rs
index 21d66d5df79..d20977d55d2 100644
--- a/src/tools/clippy/tests/ui/used_underscore_binding.rs
+++ b/src/tools/clippy/tests/ui/used_underscore_binding.rs
@@ -44,6 +44,12 @@ fn in_struct_field() {
     s._underscore_field += 1;
 }
 
+/// Tests that we do not lint if the struct field is used in code created with derive.
+#[derive(Clone, Debug)]
+pub struct UnderscoreInStruct {
+    _foo: u32,
+}
+
 /// Tests that we do not lint if the underscore is not a prefix
 fn non_prefix_underscore(some_foo: u32) -> u32 {
     some_foo + 1
diff --git a/src/tools/clippy/tests/ui/used_underscore_binding.stderr b/src/tools/clippy/tests/ui/used_underscore_binding.stderr
index 790b849210c..61a9161d212 100644
--- a/src/tools/clippy/tests/ui/used_underscore_binding.stderr
+++ b/src/tools/clippy/tests/ui/used_underscore_binding.stderr
@@ -31,7 +31,7 @@ LL |     s._underscore_field += 1;
    |     ^^^^^^^^^^^^^^^^^^^
 
 error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
-  --> $DIR/used_underscore_binding.rs:99:16
+  --> $DIR/used_underscore_binding.rs:105:16
    |
 LL |         uses_i(_i);
    |                ^^