Skip to content

Commit d397819

Browse files
authored
Rollup merge of rust-lang#102922 - kper:bugfix/102902-filtering-json, r=oli-obk
Filtering spans when emitting json According to the issue rust-lang#102902, we shouldn't emit spans which have an empty span and no suggested replacement.
2 parents b78509e + 5650673 commit d397819

File tree

4 files changed

+30
-103
lines changed

4 files changed

+30
-103
lines changed

clippy_lints/src/manual_assert.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
6969
"only a `panic!` in `if`-then statement",
7070
|diag| {
7171
// comments can be noisy, do not show them to the user
72-
diag.tool_only_span_suggestion(
73-
expr.span.shrink_to_lo(),
74-
"add comments back",
75-
comments,
76-
applicability);
72+
if !comments.is_empty() {
73+
diag.tool_only_span_suggestion(
74+
expr.span.shrink_to_lo(),
75+
"add comments back",
76+
comments,
77+
applicability);
78+
}
7779
diag.span_suggestion(
7880
expr.span,
7981
"try instead",

clippy_lints/src/needless_late_init.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,13 @@ fn assignment_suggestions<'tcx>(
180180
let suggestions = assignments
181181
.iter()
182182
.flat_map(|assignment| {
183-
[
184-
assignment.span.until(assignment.rhs_span),
185-
assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()),
186-
]
183+
let mut spans = vec![assignment.span.until(assignment.rhs_span)];
184+
185+
if assignment.rhs_span.hi() != assignment.span.hi() {
186+
spans.push(assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()));
187+
}
188+
189+
spans
187190
})
188191
.map(|span| (span, String::new()))
189192
.collect::<Vec<(Span, String)>>();

tests/ui/manual_assert.edition2018.stderr

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,65 @@ error: only a `panic!` in `if`-then statement
44
LL | / if !a.is_empty() {
55
LL | | panic!("qaqaq{:?}", a);
66
LL | | }
7-
| |_____^
7+
| |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
88
|
99
= note: `-D clippy::manual-assert` implied by `-D warnings`
10-
help: try instead
11-
|
12-
LL | assert!(a.is_empty(), "qaqaq{:?}", a);
13-
|
1410

1511
error: only a `panic!` in `if`-then statement
1612
--> $DIR/manual_assert.rs:34:5
1713
|
1814
LL | / if !a.is_empty() {
1915
LL | | panic!("qwqwq");
2016
LL | | }
21-
| |_____^
22-
|
23-
help: try instead
24-
|
25-
LL | assert!(a.is_empty(), "qwqwq");
26-
|
17+
| |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`
2718

2819
error: only a `panic!` in `if`-then statement
2920
--> $DIR/manual_assert.rs:51:5
3021
|
3122
LL | / if b.is_empty() {
3223
LL | | panic!("panic1");
3324
LL | | }
34-
| |_____^
35-
|
36-
help: try instead
37-
|
38-
LL | assert!(!b.is_empty(), "panic1");
39-
|
25+
| |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`
4026

4127
error: only a `panic!` in `if`-then statement
4228
--> $DIR/manual_assert.rs:54:5
4329
|
4430
LL | / if b.is_empty() && a.is_empty() {
4531
LL | | panic!("panic2");
4632
LL | | }
47-
| |_____^
48-
|
49-
help: try instead
50-
|
51-
LL | assert!(!(b.is_empty() && a.is_empty()), "panic2");
52-
|
33+
| |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
5334

5435
error: only a `panic!` in `if`-then statement
5536
--> $DIR/manual_assert.rs:57:5
5637
|
5738
LL | / if a.is_empty() && !b.is_empty() {
5839
LL | | panic!("panic3");
5940
LL | | }
60-
| |_____^
61-
|
62-
help: try instead
63-
|
64-
LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3");
65-
|
41+
| |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
6642

6743
error: only a `panic!` in `if`-then statement
6844
--> $DIR/manual_assert.rs:60:5
6945
|
7046
LL | / if b.is_empty() || a.is_empty() {
7147
LL | | panic!("panic4");
7248
LL | | }
73-
| |_____^
74-
|
75-
help: try instead
76-
|
77-
LL | assert!(!(b.is_empty() || a.is_empty()), "panic4");
78-
|
49+
| |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
7950

8051
error: only a `panic!` in `if`-then statement
8152
--> $DIR/manual_assert.rs:63:5
8253
|
8354
LL | / if a.is_empty() || !b.is_empty() {
8455
LL | | panic!("panic5");
8556
LL | | }
86-
| |_____^
87-
|
88-
help: try instead
89-
|
90-
LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5");
91-
|
57+
| |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
9258

9359
error: only a `panic!` in `if`-then statement
9460
--> $DIR/manual_assert.rs:66:5
9561
|
9662
LL | / if a.is_empty() {
9763
LL | | panic!("with expansion {}", one!())
9864
LL | | }
99-
| |_____^
100-
|
101-
help: try instead
102-
|
103-
LL | assert!(!a.is_empty(), "with expansion {}", one!());
104-
|
65+
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
10566

10667
error: only a `panic!` in `if`-then statement
10768
--> $DIR/manual_assert.rs:73:5

tests/ui/manual_assert.edition2021.stderr

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,65 @@ error: only a `panic!` in `if`-then statement
44
LL | / if !a.is_empty() {
55
LL | | panic!("qaqaq{:?}", a);
66
LL | | }
7-
| |_____^
7+
| |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
88
|
99
= note: `-D clippy::manual-assert` implied by `-D warnings`
10-
help: try instead
11-
|
12-
LL | assert!(a.is_empty(), "qaqaq{:?}", a);
13-
|
1410

1511
error: only a `panic!` in `if`-then statement
1612
--> $DIR/manual_assert.rs:34:5
1713
|
1814
LL | / if !a.is_empty() {
1915
LL | | panic!("qwqwq");
2016
LL | | }
21-
| |_____^
22-
|
23-
help: try instead
24-
|
25-
LL | assert!(a.is_empty(), "qwqwq");
26-
|
17+
| |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`
2718

2819
error: only a `panic!` in `if`-then statement
2920
--> $DIR/manual_assert.rs:51:5
3021
|
3122
LL | / if b.is_empty() {
3223
LL | | panic!("panic1");
3324
LL | | }
34-
| |_____^
35-
|
36-
help: try instead
37-
|
38-
LL | assert!(!b.is_empty(), "panic1");
39-
|
25+
| |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`
4026

4127
error: only a `panic!` in `if`-then statement
4228
--> $DIR/manual_assert.rs:54:5
4329
|
4430
LL | / if b.is_empty() && a.is_empty() {
4531
LL | | panic!("panic2");
4632
LL | | }
47-
| |_____^
48-
|
49-
help: try instead
50-
|
51-
LL | assert!(!(b.is_empty() && a.is_empty()), "panic2");
52-
|
33+
| |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
5334

5435
error: only a `panic!` in `if`-then statement
5536
--> $DIR/manual_assert.rs:57:5
5637
|
5738
LL | / if a.is_empty() && !b.is_empty() {
5839
LL | | panic!("panic3");
5940
LL | | }
60-
| |_____^
61-
|
62-
help: try instead
63-
|
64-
LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3");
65-
|
41+
| |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
6642

6743
error: only a `panic!` in `if`-then statement
6844
--> $DIR/manual_assert.rs:60:5
6945
|
7046
LL | / if b.is_empty() || a.is_empty() {
7147
LL | | panic!("panic4");
7248
LL | | }
73-
| |_____^
74-
|
75-
help: try instead
76-
|
77-
LL | assert!(!(b.is_empty() || a.is_empty()), "panic4");
78-
|
49+
| |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
7950

8051
error: only a `panic!` in `if`-then statement
8152
--> $DIR/manual_assert.rs:63:5
8253
|
8354
LL | / if a.is_empty() || !b.is_empty() {
8455
LL | | panic!("panic5");
8556
LL | | }
86-
| |_____^
87-
|
88-
help: try instead
89-
|
90-
LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5");
91-
|
57+
| |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
9258

9359
error: only a `panic!` in `if`-then statement
9460
--> $DIR/manual_assert.rs:66:5
9561
|
9662
LL | / if a.is_empty() {
9763
LL | | panic!("with expansion {}", one!())
9864
LL | | }
99-
| |_____^
100-
|
101-
help: try instead
102-
|
103-
LL | assert!(!a.is_empty(), "with expansion {}", one!());
104-
|
65+
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
10566

10667
error: only a `panic!` in `if`-then statement
10768
--> $DIR/manual_assert.rs:73:5

0 commit comments

Comments
 (0)