diff options
| author | bors <bors@rust-lang.org> | 2019-07-14 17:29:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-07-14 17:29:17 +0000 |
| commit | 83e4eed16ef7adb54a802e3b684427e0e912c2b7 (patch) | |
| tree | 281f9f4554f0d794245deca9f34876e4ab3cb928 /src | |
| parent | 85a360e0ea2f1629b8851e7c9b2903bbdbab42bf (diff) | |
| parent | a86aac1a672de83eae167f3cba30b5c607eca1ac (diff) | |
| download | rust-83e4eed16ef7adb54a802e3b684427e0e912c2b7.tar.gz rust-83e4eed16ef7adb54a802e3b684427e0e912c2b7.zip | |
Auto merge of #62638 - estebank:issue-62554, r=petrochenkov
Use snippet instead of pprinting statement Fix #62554.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-39848.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-62554.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-62554.stderr | 30 | ||||
| -rw-r--r-- | src/test/ui/label/label_break_value_illegal_uses.stderr | 4 |
6 files changed, 52 insertions, 22 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 83030e89af3..2666cd519f9 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4378,9 +4378,10 @@ impl<'a> Parser<'a> { Ok(Some(self.mk_item(span, ident, ItemKind::MacroDef(def), vis.clone(), attrs.to_vec()))) } - fn parse_stmt_without_recovery(&mut self, - macro_legacy_warnings: bool) - -> PResult<'a, Option<Stmt>> { + fn parse_stmt_without_recovery( + &mut self, + macro_legacy_warnings: bool, + ) -> PResult<'a, Option<Stmt>> { maybe_whole!(self, NtStmt, |x| Some(x)); let attrs = self.parse_outer_attributes()?; @@ -4586,20 +4587,15 @@ impl<'a> Parser<'a> { if self.eat(&token::Semi) { stmt_span = stmt_span.with_hi(self.prev_span.hi()); } - let sugg = pprust::to_string(|s| { - 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( - stmt_span, - "try placing this code inside a block", - sugg, - // speculative, has been misleading in the past (closed Issue #46836) - Applicability::MaybeIncorrect - ); + if let Ok(snippet) = self.sess.source_map().span_to_snippet(stmt_span) { + e.span_suggestion( + stmt_span, + "try placing this code inside a block", + format!("{{ {} }}", snippet), + // speculative, has been misleading in the past (#46836) + Applicability::MaybeIncorrect, + ); + } } Err(mut e) => { self.recover_stmt_(SemiColonMode::Break, BlockMode::Ignore); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 3b6064fcdf7..0e3ce2787f3 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -745,8 +745,7 @@ impl<'a> State<'a> { self.bclose_maybe_open(span, true) } - crate fn break_offset_if_not_bol(&mut self, n: usize, - off: isize) { + crate fn break_offset_if_not_bol(&mut self, n: usize, off: isize) { if !self.s.is_beginning_of_line() { self.s.break_offset(n, off) } else { diff --git a/src/test/ui/issues/issue-39848.stderr b/src/test/ui/issues/issue-39848.stderr index 6eda03c1a08..fa87967432d 100644 --- a/src/test/ui/issues/issue-39848.stderr +++ b/src/test/ui/issues/issue-39848.stderr @@ -2,7 +2,7 @@ error: expected `{`, found `foo` --> $DIR/issue-39848.rs:8:19 | 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 ... diff --git a/src/test/ui/issues/issue-62554.rs b/src/test/ui/issues/issue-62554.rs new file mode 100644 index 00000000000..3d50674e624 --- /dev/null +++ b/src/test/ui/issues/issue-62554.rs @@ -0,0 +1,5 @@ +fn main() {} + +fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { +//~^ ERROR expected `{`, found `macro_rules` +//~ ERROR this file contains an un-closed delimiter diff --git a/src/test/ui/issues/issue-62554.stderr b/src/test/ui/issues/issue-62554.stderr new file mode 100644 index 00000000000..9675d540e72 --- /dev/null +++ b/src/test/ui/issues/issue-62554.stderr @@ -0,0 +1,30 @@ +error: this file contains an un-closed delimiter + --> $DIR/issue-62554.rs:5:53 + | +LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { + | - - - - - un-closed delimiter + | | | | | + | | | | un-closed delimiter + | | | un-closed delimiter + | un-closed delimiter un-closed delimiter +LL | +LL | + | ^ + +error: expected `{`, found `macro_rules` + --> $DIR/issue-62554.rs:3:23 + | +LL | fn foo(u: u8) { if u8 macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { + | -- ^^^^^^^^^^^ expected `{` + | | + | this `if` statement has a condition, but no block +help: try placing this code inside a block + | +LL | fn foo(u: u8) { if u8 { macro_rules! u8 { (u6) => { fn uuuuuuuuuuu() { use s loo mod u8 { +LL | +LL | +LL | } + | + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/label/label_break_value_illegal_uses.stderr b/src/test/ui/label/label_break_value_illegal_uses.stderr index 0b9754c3c70..80b4329ad40 100644 --- a/src/test/ui/label/label_break_value_illegal_uses.stderr +++ b/src/test/ui/label/label_break_value_illegal_uses.stderr @@ -11,7 +11,7 @@ LL | if true 'b: {} | -- ^^---- | | | | | expected `{` - | | help: try placing this code inside a block: `{ 'b: { } }` + | | help: try placing this code inside a block: `{ 'b: {} }` | this `if` statement has a condition, but no block error: expected `{`, found `'b` @@ -21,7 +21,7 @@ LL | if true {} else 'b: {} | ^^---- | | | expected `{` - | help: try placing this code inside a block: `{ 'b: { } }` + | help: try placing this code inside a block: `{ 'b: {} }` error: expected one of `.`, `?`, `{`, or an operator, found `'b` --> $DIR/label_break_value_illegal_uses.rs:18:17 |
