Skip to content

Commit

Permalink
use suggestions instead of helps with code in them
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 31, 2017
1 parent 0c85f2a commit d73e84d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/librustc_const_eval/eval.rs
Expand Up @@ -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::*;
Expand Down
27 changes: 23 additions & 4 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/missing-block-hint.rs
Expand Up @@ -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; }
}
}
3 changes: 2 additions & 1 deletion src/test/parse-fail/tuple-float-index.rs
Expand Up @@ -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
}

0 comments on commit d73e84d

Please sign in to comment.