about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-02-02 21:58:10 +0000
committerbors <bors@rust-lang.org>2017-02-02 21:58:10 +0000
commiteedaa94e330094a84f4df9aa52949515327f8e80 (patch)
tree6aecbbce96b60f7526484eab622ad2817fc55dfc /src/libsyntax/parse/parser.rs
parenta47a6ea771ca4426b6bba29219bdc7d2bceec3d5 (diff)
parentd09e4de640de7632f82f034ef48f73e4ec0ea4ca (diff)
downloadrust-eedaa94e330094a84f4df9aa52949515327f8e80.tar.gz
rust-eedaa94e330094a84f4df9aa52949515327f8e80.zip
Auto merge of #39470 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 9 pull requests

- Successful merges: #38823, #39196, #39299, #39319, #39373, #39383, #39416, #39420, #39427
- Failed merges:
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 3480db8ec3b..2532a1def7d 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2456,9 +2456,21 @@ impl<'a> Parser<'a> {
                             Some(f) => f,
                             None => continue,
                         };
-                        err.help(&format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
-                                 float.trunc() as usize,
-                                 format!(".{}", fstr.splitn(2, ".").last().unwrap())));
+                        let sugg = pprust::to_string(|s| {
+                            use print::pprust::PrintState;
+                            use print::pp::word;
+                            s.popen()?;
+                            s.print_expr(&e)?;
+                            word(&mut s.s, ".")?;
+                            s.print_usize(float.trunc() as usize)?;
+                            s.pclose()?;
+                            word(&mut s.s, ".")?;
+                            word(&mut s.s, fstr.splitn(2, ".").last().unwrap())
+                        });
+                        err.span_suggestion(
+                            prev_span,
+                            "try parenthesizing the first index",
+                            sugg);
                     }
                     return Err(err);
 
@@ -3900,7 +3912,14 @@ impl<'a> Parser<'a> {
                     if self.eat(&token::Semi) {
                         stmt_span.hi = self.prev_span.hi;
                     }
-                    e.span_help(stmt_span, "try placing this code inside a block");
+                    let sugg = pprust::to_string(|s| {
+                        use print::pprust::{PrintState, INDENT_UNIT};
+                        s.ibox(INDENT_UNIT)?;
+                        s.bopen()?;
+                        s.print_stmt(&stmt)?;
+                        s.bclose_maybe_open(stmt.span, INDENT_UNIT, false)
+                    });
+                    e.span_suggestion(stmt_span, "try placing this code inside a block", sugg);
                 }
                 Err(mut e) => {
                     self.recover_stmt_(SemiColonMode::Break);