Fix the wrong suggestion when using macro in collapsible_if

This commit is contained in:
Takayuki Nakata 2020-09-01 00:05:53 +09:00
parent 001c1c51d2
commit 001f9e45f2
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