Skip to content

Commit d295067

Browse files
committed
Don't lint code from external macros
1 parent 15ed281 commit d295067

9 files changed

+75
-21
lines changed

clippy_lints/src/misc_early/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ impl EarlyLintPass for MiscEarlyLints {
339339
}
340340

341341
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) {
342+
if in_external_macro(cx.sess(), pat.span) {
343+
return;
344+
}
345+
342346
unneeded_field_pattern::check(cx, pat);
343347
redundant_pattern::check(cx, pat);
344348
unneeded_wildcard_pattern::check(cx, pat);

tests/ui/patterns.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//@run-rustfix
2+
//@aux-build:proc_macros.rs:proc-macro
23
#![warn(clippy::all)]
34
#![allow(unused)]
45
#![allow(clippy::uninlined_format_args)]
56

7+
#[macro_use]
8+
extern crate proc_macros;
9+
610
fn main() {
711
let v = Some(true);
812
let s = [0, 1, 2, 3, 4];
@@ -34,4 +38,11 @@ fn main() {
3438
ref x => println!("vec: {:?}", x),
3539
ref y if y == &vec![0] => (),
3640
}
41+
external! {
42+
let v = Some(true);
43+
match v {
44+
Some(x) => (),
45+
y @ _ => (),
46+
}
47+
}
3748
}

tests/ui/patterns.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//@run-rustfix
2+
//@aux-build:proc_macros.rs:proc-macro
23
#![warn(clippy::all)]
34
#![allow(unused)]
45
#![allow(clippy::uninlined_format_args)]
56

7+
#[macro_use]
8+
extern crate proc_macros;
9+
610
fn main() {
711
let v = Some(true);
812
let s = [0, 1, 2, 3, 4];
@@ -34,4 +38,11 @@ fn main() {
3438
ref x @ _ => println!("vec: {:?}", x),
3539
ref y if y == &vec![0] => (),
3640
}
41+
external! {
42+
let v = Some(true);
43+
match v {
44+
Some(x) => (),
45+
y @ _ => (),
46+
}
47+
}
3748
}

tests/ui/patterns.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error: the `y @ _` pattern can be written as just `y`
2-
--> $DIR/patterns.rs:11:9
2+
--> $DIR/patterns.rs:15:9
33
|
44
LL | y @ _ => (),
55
| ^^^^^ help: try: `y`
66
|
77
= note: `-D clippy::redundant-pattern` implied by `-D warnings`
88

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

1515
error: the `x @ _` pattern can be written as just `x`
16-
--> $DIR/patterns.rs:34:9
16+
--> $DIR/patterns.rs:38:9
1717
|
1818
LL | ref x @ _ => println!("vec: {:?}", x),
1919
| ^^^^^^^^^ help: try: `ref x`

tests/ui/unneeded_field_pattern.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
//@aux-build:proc_macros.rs:proc-macro
12
#![warn(clippy::unneeded_field_pattern)]
2-
#[allow(dead_code, unused)]
3+
#![allow(dead_code, unused)]
4+
5+
#[macro_use]
6+
extern crate proc_macros;
37

48
struct Foo {
59
a: i32,
@@ -19,4 +23,12 @@ fn main() {
1923
Foo { b: 0, .. } => {}, // should be OK
2024
Foo { .. } => {}, // and the Force might be with this one
2125
}
26+
external! {
27+
let f = Foo { a: 0, b: 0, c: 0 };
28+
match f {
29+
Foo { a: _, b: 0, .. } => {},
30+
31+
Foo { a: _, b: _, c: _ } => {},
32+
}
33+
}
2234
}

tests/ui/unneeded_field_pattern.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: you matched a field with a wildcard pattern, consider using `..` instead
2-
--> $DIR/unneeded_field_pattern.rs:14:15
2+
--> $DIR/unneeded_field_pattern.rs:18:15
33
|
44
LL | Foo { a: _, b: 0, .. } => {},
55
| ^^^^
@@ -8,7 +8,7 @@ LL | Foo { a: _, b: 0, .. } => {},
88
= note: `-D clippy::unneeded-field-pattern` implied by `-D warnings`
99

1010
error: all the struct fields are matched to a wildcard pattern, consider using `..`
11-
--> $DIR/unneeded_field_pattern.rs:16:9
11+
--> $DIR/unneeded_field_pattern.rs:20:9
1212
|
1313
LL | Foo { a: _, b: _, c: _ } => {},
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/unneeded_wildcard_pattern.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//@run-rustfix
2+
//@aux-build:proc_macros.rs:proc-macro
23
#![feature(stmt_expr_attributes)]
34
#![deny(clippy::unneeded_wildcard_pattern)]
45
#![allow(clippy::needless_if)]
56

7+
#[macro_use]
8+
extern crate proc_macros;
9+
610
fn main() {
711
let t = (0, 1, 2, 3);
812

@@ -43,4 +47,8 @@ fn main() {
4347
{
4448
if let S(0, ..,) = s {};
4549
}
50+
external! {
51+
let t = (0, 1, 2, 3);
52+
if let (0, _, ..) = t {};
53+
}
4654
}

tests/ui/unneeded_wildcard_pattern.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//@run-rustfix
2+
//@aux-build:proc_macros.rs:proc-macro
23
#![feature(stmt_expr_attributes)]
34
#![deny(clippy::unneeded_wildcard_pattern)]
45
#![allow(clippy::needless_if)]
56

7+
#[macro_use]
8+
extern crate proc_macros;
9+
610
fn main() {
711
let t = (0, 1, 2, 3);
812

@@ -43,4 +47,8 @@ fn main() {
4347
{
4448
if let S(0, .., _, _,) = s {};
4549
}
50+
external! {
51+
let t = (0, 1, 2, 3);
52+
if let (0, _, ..) = t {};
53+
}
4654
}

tests/ui/unneeded_wildcard_pattern.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
11
error: this pattern is unneeded as the `..` pattern can match that element
2-
--> $DIR/unneeded_wildcard_pattern.rs:9:18
2+
--> $DIR/unneeded_wildcard_pattern.rs:13:18
33
|
44
LL | if let (0, .., _) = t {};
55
| ^^^ help: remove it
66
|
77
note: the lint level is defined here
8-
--> $DIR/unneeded_wildcard_pattern.rs:3:9
8+
--> $DIR/unneeded_wildcard_pattern.rs:4:9
99
|
1010
LL | #![deny(clippy::unneeded_wildcard_pattern)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

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

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)