Use snippet instead of pprinting statement
This commit is contained in:
parent
4bb6b4a5ed
commit
726aa1437f
4 changed files with 17 additions and 22 deletions
|
@ -4378,9 +4378,10 @@ impl<'a> Parser<'a> {
|
||||||
Ok(Some(self.mk_item(span, ident, ItemKind::MacroDef(def), vis.clone(), attrs.to_vec())))
|
Ok(Some(self.mk_item(span, ident, ItemKind::MacroDef(def), vis.clone(), attrs.to_vec())))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_stmt_without_recovery(&mut self,
|
fn parse_stmt_without_recovery(
|
||||||
macro_legacy_warnings: bool)
|
&mut self,
|
||||||
-> PResult<'a, Option<Stmt>> {
|
macro_legacy_warnings: bool,
|
||||||
|
) -> PResult<'a, Option<Stmt>> {
|
||||||
maybe_whole!(self, NtStmt, |x| Some(x));
|
maybe_whole!(self, NtStmt, |x| Some(x));
|
||||||
|
|
||||||
let attrs = self.parse_outer_attributes()?;
|
let attrs = self.parse_outer_attributes()?;
|
||||||
|
@ -4586,21 +4587,16 @@ impl<'a> Parser<'a> {
|
||||||
if self.eat(&token::Semi) {
|
if self.eat(&token::Semi) {
|
||||||
stmt_span = stmt_span.with_hi(self.prev_span.hi());
|
stmt_span = stmt_span.with_hi(self.prev_span.hi());
|
||||||
}
|
}
|
||||||
let sugg = pprust::to_string(|s| {
|
if let Ok(snippet) = self.sess.source_map().span_to_snippet(stmt_span) {
|
||||||
use crate::print::pprust::INDENT_UNIT;
|
|
||||||
s.ibox(INDENT_UNIT);
|
|
||||||
s.bopen();
|
|
||||||
s.print_stmt(&stmt);
|
|
||||||
s.bclose_maybe_open(stmt.span, false)
|
|
||||||
});
|
|
||||||
e.span_suggestion(
|
e.span_suggestion(
|
||||||
stmt_span,
|
stmt_span,
|
||||||
"try placing this code inside a block",
|
"try placing this code inside a block",
|
||||||
sugg,
|
format!("{{ {} }}", snippet),
|
||||||
// speculative, has been misleading in the past (closed Issue #46836)
|
// speculative, has been misleading in the past (#46836)
|
||||||
Applicability::MaybeIncorrect
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Err(mut e) => {
|
Err(mut e) => {
|
||||||
self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
|
self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore);
|
||||||
self.cancel(&mut e);
|
self.cancel(&mut e);
|
||||||
|
|
|
@ -745,8 +745,7 @@ impl<'a> State<'a> {
|
||||||
self.bclose_maybe_open(span, true)
|
self.bclose_maybe_open(span, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn break_offset_if_not_bol(&mut self, n: usize,
|
crate fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
|
||||||
off: isize) {
|
|
||||||
if !self.s.is_beginning_of_line() {
|
if !self.s.is_beginning_of_line() {
|
||||||
self.s.break_offset(n, off)
|
self.s.break_offset(n, off)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: expected `{`, found `foo`
|
||||||
--> $DIR/issue-39848.rs:8:19
|
--> $DIR/issue-39848.rs:8:19
|
||||||
|
|
|
|
||||||
LL | if $tgt.has_$field() {}
|
LL | if $tgt.has_$field() {}
|
||||||
| -- - help: try placing this code inside a block: `{ foo(); }`
|
| -- - help: try placing this code inside a block: `{ ) }`
|
||||||
| |
|
| |
|
||||||
| this `if` statement has a condition, but no block
|
| this `if` statement has a condition, but no block
|
||||||
...
|
...
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue