Auto merge of #5992 - giraffate:fix_wrong_seggestion_in_collapsible_if, r=yaahc

Fix the wrong suggestion when using macro in `collapsible_if`

Fix #5962

changelog: Fix the wrong suggestion when using macro in `collapsible_if`
This commit is contained in:
bors 2020-08-31 19:41:13 +00:00
commit 066f105d67
4 changed files with 22 additions and 2 deletions

View file

@ -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(..)

View file

@ -135,4 +135,7 @@ fn main() {
if truth() {}
}
}
// Fix #5962
if matches!(true, true) && matches!(true, true) {}
}

View file

@ -149,4 +149,9 @@ fn main() {
if truth() {}
}
}
// Fix #5962
if matches!(true, true) {
if matches!(true, true) {}
}
}

View file

@ -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