Skip to content

Commit

Permalink
Fix the wrong suggestion when using macro in collapsible_if
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate committed Aug 31, 2020
1 parent 001c1c5 commit 001f9e4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion clippy_lints/src/utils/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ impl<'a> Sugg<'a> {
pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self {
use rustc_ast::ast::RangeLimits;

let snippet = snippet(cx, expr.span, default);
let snippet = if expr.span.from_expansion() {
snippet_with_macro_callsite(cx, expr.span, default)
} else {
snippet(cx, expr.span, default)
};

match expr.kind {
ast::ExprKind::AddrOf(..)
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/collapsible_if.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ fn main() {
if truth() {}
}
}

// Fix #5962
if matches!(true, true) && matches!(true, true) {}
}
5 changes: 5 additions & 0 deletions tests/ui/collapsible_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,9 @@ fn main() {
if truth() {}
}
}

// Fix #5962
if matches!(true, true) {
if matches!(true, true) {}
}
}
10 changes: 9 additions & 1 deletion tests/ui/collapsible_if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,13 @@ LL | println!("Hello world!");
LL | }
|

error: aborting due to 7 previous errors
error: this `if` statement can be collapsed
--> $DIR/collapsible_if.rs:154:5
|
LL | / if matches!(true, true) {
LL | | if matches!(true, true) {}
LL | | }
| |_____^ help: collapse nested if block: `if matches!(true, true) && matches!(true, true) {}`

error: aborting due to 8 previous errors

0 comments on commit 001f9e4

Please sign in to comment.