"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",
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)>>();
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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