use suggestions instead of helps with code in them
This commit is contained in:
parent
0c85f2a1bd
commit
d73e84d2e7
4 changed files with 27 additions and 8 deletions
|
@ -8,8 +8,6 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
//#![allow(non_camel_case_types)]
|
|
||||||
|
|
||||||
use rustc::middle::const_val::ConstVal::*;
|
use rustc::middle::const_val::ConstVal::*;
|
||||||
use rustc::middle::const_val::ConstVal;
|
use rustc::middle::const_val::ConstVal;
|
||||||
use self::ErrKind::*;
|
use self::ErrKind::*;
|
||||||
|
|
|
@ -2456,9 +2456,21 @@ impl<'a> Parser<'a> {
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
err.help(&format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
|
let sugg = pprust::to_string(|s| {
|
||||||
float.trunc() as usize,
|
use print::pprust::PrintState;
|
||||||
format!(".{}", fstr.splitn(2, ".").last().unwrap())));
|
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);
|
return Err(err);
|
||||||
|
|
||||||
|
@ -3900,7 +3912,14 @@ impl<'a> Parser<'a> {
|
||||||
if self.eat(&token::Semi) {
|
if self.eat(&token::Semi) {
|
||||||
stmt_span.hi = self.prev_span.hi;
|
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) => {
|
Err(mut e) => {
|
||||||
self.recover_stmt_(SemiColonMode::Break);
|
self.recover_stmt_(SemiColonMode::Break);
|
||||||
|
|
|
@ -15,6 +15,7 @@ fn main() {
|
||||||
{
|
{
|
||||||
if (foo)
|
if (foo)
|
||||||
bar; //~ ERROR expected `{`, found `bar`
|
bar; //~ ERROR expected `{`, found `bar`
|
||||||
//^ HELP try placing this code inside a block
|
//~^ HELP try placing this code inside a block
|
||||||
|
//~| SUGGESTION { bar; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,6 @@
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
(1, (2, 3)).1.1; //~ ERROR unexpected token
|
(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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue