From d73e84d2e7a7733d507ed7a3a44af4ab7941ce88 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 31 Jan 2017 14:45:08 +0100 Subject: [PATCH] use suggestions instead of helps with code in them --- src/librustc_const_eval/eval.rs | 2 -- src/libsyntax/parse/parser.rs | 27 ++++++++++++++++++--- src/test/compile-fail/missing-block-hint.rs | 3 ++- src/test/parse-fail/tuple-float-index.rs | 3 ++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index a9dcb1ed89613..47a98155fc4b0 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//#![allow(non_camel_case_types)] - use rustc::middle::const_val::ConstVal::*; use rustc::middle::const_val::ConstVal; use self::ErrKind::*; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3480db8ec3b7d..2532a1def7dda 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); diff --git a/src/test/compile-fail/missing-block-hint.rs b/src/test/compile-fail/missing-block-hint.rs index 1f29ff4e05c09..6a140e6f21c19 100644 --- a/src/test/compile-fail/missing-block-hint.rs +++ b/src/test/compile-fail/missing-block-hint.rs @@ -15,6 +15,7 @@ fn main() { { if (foo) bar; //~ ERROR expected `{`, found `bar` - //^ HELP try placing this code inside a block + //~^ HELP try placing this code inside a block + //~| SUGGESTION { bar; } } } diff --git a/src/test/parse-fail/tuple-float-index.rs b/src/test/parse-fail/tuple-float-index.rs index f3f5e35634682..57ad89ad37404 100644 --- a/src/test/parse-fail/tuple-float-index.rs +++ b/src/test/parse-fail/tuple-float-index.rs @@ -12,5 +12,6 @@ fn main () { (1, (2, 3)).1.1; //~ ERROR unexpected token - //~^ HELP try parenthesizing the first index; e.g., `(foo.1).1` + //~^ HELP try parenthesizing the first index + //~| SUGGESTION ((1, (2, 3)).1).1 }