Skip to content

Don't lint code from external macros for 8 lints #11009

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

Merged
merged 1 commit into from
Jun 27, 2023
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
4 changes: 4 additions & 0 deletions clippy_lints/src/misc_early/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ impl EarlyLintPass for MiscEarlyLints {
}

fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) {
if in_external_macro(cx.sess(), pat.span) {
return;
}

unneeded_field_pattern::check(cx, pat);
redundant_pattern::check(cx, pat);
unneeded_wildcard_pattern::check(cx, pat);
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/patterns.fixed
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//@run-rustfix
//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::all)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args)]

#[macro_use]
extern crate proc_macros;

fn main() {
let v = Some(true);
let s = [0, 1, 2, 3, 4];
Expand Down Expand Up @@ -34,4 +38,11 @@ fn main() {
ref x => println!("vec: {:?}", x),
ref y if y == &vec![0] => (),
}
external! {
let v = Some(true);
match v {
Some(x) => (),
y @ _ => (),
}
}
}
11 changes: 11 additions & 0 deletions tests/ui/patterns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//@run-rustfix
//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::all)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args)]

#[macro_use]
extern crate proc_macros;

fn main() {
let v = Some(true);
let s = [0, 1, 2, 3, 4];
Expand Down Expand Up @@ -34,4 +38,11 @@ fn main() {
ref x @ _ => println!("vec: {:?}", x),
ref y if y == &vec![0] => (),
}
external! {
let v = Some(true);
match v {
Some(x) => (),
y @ _ => (),
}
}
}
6 changes: 3 additions & 3 deletions tests/ui/patterns.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error: the `y @ _` pattern can be written as just `y`
--> $DIR/patterns.rs:11:9
--> $DIR/patterns.rs:15:9
|
LL | y @ _ => (),
| ^^^^^ help: try: `y`
|
= note: `-D clippy::redundant-pattern` implied by `-D warnings`

error: the `x @ _` pattern can be written as just `x`
--> $DIR/patterns.rs:26:9
--> $DIR/patterns.rs:30:9
|
LL | ref mut x @ _ => {
| ^^^^^^^^^^^^^ help: try: `ref mut x`

error: the `x @ _` pattern can be written as just `x`
--> $DIR/patterns.rs:34:9
--> $DIR/patterns.rs:38:9
|
LL | ref x @ _ => println!("vec: {:?}", x),
| ^^^^^^^^^ help: try: `ref x`
Expand Down
14 changes: 13 additions & 1 deletion tests/ui/unneeded_field_pattern.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::unneeded_field_pattern)]
#[allow(dead_code, unused)]
#![allow(dead_code, unused)]

#[macro_use]
extern crate proc_macros;

struct Foo {
a: i32,
Expand All @@ -19,4 +23,12 @@ fn main() {
Foo { b: 0, .. } => {}, // should be OK
Foo { .. } => {}, // and the Force might be with this one
}
external! {
let f = Foo { a: 0, b: 0, c: 0 };
match f {
Foo { a: _, b: 0, .. } => {},

Foo { a: _, b: _, c: _ } => {},
}
}
}
4 changes: 2 additions & 2 deletions tests/ui/unneeded_field_pattern.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: you matched a field with a wildcard pattern, consider using `..` instead
--> $DIR/unneeded_field_pattern.rs:14:15
--> $DIR/unneeded_field_pattern.rs:18:15
|
LL | Foo { a: _, b: 0, .. } => {},
| ^^^^
Expand All @@ -8,7 +8,7 @@ LL | Foo { a: _, b: 0, .. } => {},
= note: `-D clippy::unneeded-field-pattern` implied by `-D warnings`

error: all the struct fields are matched to a wildcard pattern, consider using `..`
--> $DIR/unneeded_field_pattern.rs:16:9
--> $DIR/unneeded_field_pattern.rs:20:9
|
LL | Foo { a: _, b: _, c: _ } => {},
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/unneeded_wildcard_pattern.fixed
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//@run-rustfix
//@aux-build:proc_macros.rs:proc-macro
#![feature(stmt_expr_attributes)]
#![deny(clippy::unneeded_wildcard_pattern)]
#![allow(clippy::needless_if)]

#[macro_use]
extern crate proc_macros;

fn main() {
let t = (0, 1, 2, 3);

Expand Down Expand Up @@ -43,4 +47,8 @@ fn main() {
{
if let S(0, ..,) = s {};
}
external! {
let t = (0, 1, 2, 3);
if let (0, _, ..) = t {};
}
}
8 changes: 8 additions & 0 deletions tests/ui/unneeded_wildcard_pattern.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//@run-rustfix
//@aux-build:proc_macros.rs:proc-macro
#![feature(stmt_expr_attributes)]
#![deny(clippy::unneeded_wildcard_pattern)]
#![allow(clippy::needless_if)]

#[macro_use]
extern crate proc_macros;

fn main() {
let t = (0, 1, 2, 3);

Expand Down Expand Up @@ -43,4 +47,8 @@ fn main() {
{
if let S(0, .., _, _,) = s {};
}
external! {
let t = (0, 1, 2, 3);
if let (0, _, ..) = t {};
}
}
30 changes: 15 additions & 15 deletions tests/ui/unneeded_wildcard_pattern.stderr
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
error: this pattern is unneeded as the `..` pattern can match that element
--> $DIR/unneeded_wildcard_pattern.rs:9:18
--> $DIR/unneeded_wildcard_pattern.rs:13:18
|
LL | if let (0, .., _) = t {};
| ^^^ help: remove it
|
note: the lint level is defined here
--> $DIR/unneeded_wildcard_pattern.rs:3:9
--> $DIR/unneeded_wildcard_pattern.rs:4:9
|
LL | #![deny(clippy::unneeded_wildcard_pattern)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this pattern is unneeded as the `..` pattern can match that element
--> $DIR/unneeded_wildcard_pattern.rs:10:16
--> $DIR/unneeded_wildcard_pattern.rs:14:16
|
LL | if let (0, _, ..) = t {};
| ^^^ help: remove it

error: this pattern is unneeded as the `..` pattern can match that element
--> $DIR/unneeded_wildcard_pattern.rs:11:13
--> $DIR/unneeded_wildcard_pattern.rs:15:13
|
LL | if let (_, .., 0) = t {};
| ^^^ help: remove it

error: this pattern is unneeded as the `..` pattern can match that element
--> $DIR/unneeded_wildcard_pattern.rs:12:15
--> $DIR/unneeded_wildcard_pattern.rs:16:15
|
LL | if let (.., _, 0) = t {};
| ^^^ help: remove it

error: these patterns are unneeded as the `..` pattern can match those elements
--> $DIR/unneeded_wildcard_pattern.rs:13:16
--> $DIR/unneeded_wildcard_pattern.rs:17:16
|
LL | if let (0, _, _, ..) = t {};
| ^^^^^^ help: remove them

error: these patterns are unneeded as the `..` pattern can match those elements
--> $DIR/unneeded_wildcard_pattern.rs:14:18
--> $DIR/unneeded_wildcard_pattern.rs:18:18
|
LL | if let (0, .., _, _) = t {};
| ^^^^^^ help: remove them

error: these patterns are unneeded as the `..` pattern can match those elements
--> $DIR/unneeded_wildcard_pattern.rs:23:22
--> $DIR/unneeded_wildcard_pattern.rs:27:22
|
LL | if let (0, .., _, _,) = t {};
| ^^^^^^ help: remove them

error: this pattern is unneeded as the `..` pattern can match that element
--> $DIR/unneeded_wildcard_pattern.rs:30:19
--> $DIR/unneeded_wildcard_pattern.rs:34:19
|
LL | if let S(0, .., _) = s {};
| ^^^ help: remove it

error: this pattern is unneeded as the `..` pattern can match that element
--> $DIR/unneeded_wildcard_pattern.rs:31:17
--> $DIR/unneeded_wildcard_pattern.rs:35:17
|
LL | if let S(0, _, ..) = s {};
| ^^^ help: remove it

error: this pattern is unneeded as the `..` pattern can match that element
--> $DIR/unneeded_wildcard_pattern.rs:32:14
--> $DIR/unneeded_wildcard_pattern.rs:36:14
|
LL | if let S(_, .., 0) = s {};
| ^^^ help: remove it

error: this pattern is unneeded as the `..` pattern can match that element
--> $DIR/unneeded_wildcard_pattern.rs:33:16
--> $DIR/unneeded_wildcard_pattern.rs:37:16
|
LL | if let S(.., _, 0) = s {};
| ^^^ help: remove it

error: these patterns are unneeded as the `..` pattern can match those elements
--> $DIR/unneeded_wildcard_pattern.rs:34:17
--> $DIR/unneeded_wildcard_pattern.rs:38:17
|
LL | if let S(0, _, _, ..) = s {};
| ^^^^^^ help: remove them

error: these patterns are unneeded as the `..` pattern can match those elements
--> $DIR/unneeded_wildcard_pattern.rs:35:19
--> $DIR/unneeded_wildcard_pattern.rs:39:19
|
LL | if let S(0, .., _, _) = s {};
| ^^^^^^ help: remove them

error: these patterns are unneeded as the `..` pattern can match those elements
--> $DIR/unneeded_wildcard_pattern.rs:44:23
--> $DIR/unneeded_wildcard_pattern.rs:48:23
|
LL | if let S(0, .., _, _,) = s {};
| ^^^^^^ help: remove them
Expand Down