Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for and fix rust-lang/rust-clippy#9131 #99026

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions src/tools/clippy/tests/ui/used_underscore_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/used_underscore_binding.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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);
| ^^
Expand Down