mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Rollup merge of #102922 - kper:bugfix/102902-filtering-json, r=oli-obk
Filtering spans when emitting json According to the issue #102902, we shouldn't emit spans which have an empty span and no suggested replacement.
This commit is contained in:
commit
d3978198ac
4 changed files with 30 additions and 103 deletions
|
@ -69,11 +69,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
|
|||
"only a `panic!` in `if`-then statement",
|
||||
|diag| {
|
||||
// comments can be noisy, do not show them to the user
|
||||
diag.tool_only_span_suggestion(
|
||||
expr.span.shrink_to_lo(),
|
||||
"add comments back",
|
||||
comments,
|
||||
applicability);
|
||||
if !comments.is_empty() {
|
||||
diag.tool_only_span_suggestion(
|
||||
expr.span.shrink_to_lo(),
|
||||
"add comments back",
|
||||
comments,
|
||||
applicability);
|
||||
}
|
||||
diag.span_suggestion(
|
||||
expr.span,
|
||||
"try instead",
|
||||
|
|
|
@ -180,10 +180,13 @@ fn assignment_suggestions<'tcx>(
|
|||
let suggestions = assignments
|
||||
.iter()
|
||||
.flat_map(|assignment| {
|
||||
[
|
||||
assignment.span.until(assignment.rhs_span),
|
||||
assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()),
|
||||
]
|
||||
let mut spans = vec![assignment.span.until(assignment.rhs_span)];
|
||||
|
||||
if assignment.rhs_span.hi() != assignment.span.hi() {
|
||||
spans.push(assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()));
|
||||
}
|
||||
|
||||
spans
|
||||
})
|
||||
.map(|span| (span, String::new()))
|
||||
.collect::<Vec<(Span, String)>>();
|
||||
|
|
|
@ -4,13 +4,9 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if !a.is_empty() {
|
||||
LL | | panic!("qaqaq{:?}", a);
|
||||
LL | | }
|
||||
| |_____^
|
||||
| |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
|
||||
|
|
||||
= note: `-D clippy::manual-assert` implied by `-D warnings`
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(a.is_empty(), "qaqaq{:?}", a);
|
||||
|
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:34:5
|
||||
|
@ -18,12 +14,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if !a.is_empty() {
|
||||
LL | | panic!("qwqwq");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(a.is_empty(), "qwqwq");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:51:5
|
||||
|
@ -31,12 +22,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if b.is_empty() {
|
||||
LL | | panic!("panic1");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!b.is_empty(), "panic1");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:54:5
|
||||
|
@ -44,12 +30,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if b.is_empty() && a.is_empty() {
|
||||
LL | | panic!("panic2");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!(b.is_empty() && a.is_empty()), "panic2");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:57:5
|
||||
|
@ -57,12 +38,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if a.is_empty() && !b.is_empty() {
|
||||
LL | | panic!("panic3");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:60:5
|
||||
|
@ -70,12 +46,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if b.is_empty() || a.is_empty() {
|
||||
LL | | panic!("panic4");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!(b.is_empty() || a.is_empty()), "panic4");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:63:5
|
||||
|
@ -83,12 +54,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if a.is_empty() || !b.is_empty() {
|
||||
LL | | panic!("panic5");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:66:5
|
||||
|
@ -96,12 +62,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if a.is_empty() {
|
||||
LL | | panic!("with expansion {}", one!())
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!a.is_empty(), "with expansion {}", one!());
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:73:5
|
||||
|
|
|
@ -4,13 +4,9 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if !a.is_empty() {
|
||||
LL | | panic!("qaqaq{:?}", a);
|
||||
LL | | }
|
||||
| |_____^
|
||||
| |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
|
||||
|
|
||||
= note: `-D clippy::manual-assert` implied by `-D warnings`
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(a.is_empty(), "qaqaq{:?}", a);
|
||||
|
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:34:5
|
||||
|
@ -18,12 +14,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if !a.is_empty() {
|
||||
LL | | panic!("qwqwq");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(a.is_empty(), "qwqwq");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:51:5
|
||||
|
@ -31,12 +22,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if b.is_empty() {
|
||||
LL | | panic!("panic1");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!b.is_empty(), "panic1");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:54:5
|
||||
|
@ -44,12 +30,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if b.is_empty() && a.is_empty() {
|
||||
LL | | panic!("panic2");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!(b.is_empty() && a.is_empty()), "panic2");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:57:5
|
||||
|
@ -57,12 +38,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if a.is_empty() && !b.is_empty() {
|
||||
LL | | panic!("panic3");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:60:5
|
||||
|
@ -70,12 +46,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if b.is_empty() || a.is_empty() {
|
||||
LL | | panic!("panic4");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!(b.is_empty() || a.is_empty()), "panic4");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:63:5
|
||||
|
@ -83,12 +54,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if a.is_empty() || !b.is_empty() {
|
||||
LL | | panic!("panic5");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5");
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:66:5
|
||||
|
@ -96,12 +62,7 @@ error: only a `panic!` in `if`-then statement
|
|||
LL | / if a.is_empty() {
|
||||
LL | | panic!("with expansion {}", one!())
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: try instead
|
||||
|
|
||||
LL | assert!(!a.is_empty(), "with expansion {}", one!());
|
||||
|
|
||||
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
|
||||
|
||||
error: only a `panic!` in `if`-then statement
|
||||
--> $DIR/manual_assert.rs:73:5
|
||||
|
|
Loading…
Reference in a new issue