Skip to content

Commit a561ad8

Browse files
Rollup merge of #39420 - oli-obk:sugg, r=pnkfelix
parser: use suggestions instead of helps with code in them
2 parents 9559c4d + d73e84d commit a561ad8

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/librustc_const_eval/eval.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//#![allow(non_camel_case_types)]
12-
1311
use rustc::middle::const_val::ConstVal::*;
1412
use rustc::middle::const_val::ConstVal;
1513
use self::ErrKind::*;

src/libsyntax/parse/parser.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -2456,9 +2456,21 @@ impl<'a> Parser<'a> {
24562456
Some(f) => f,
24572457
None => continue,
24582458
};
2459-
err.help(&format!("try parenthesizing the first index; e.g., `(foo.{}){}`",
2460-
float.trunc() as usize,
2461-
format!(".{}", fstr.splitn(2, ".").last().unwrap())));
2459+
let sugg = pprust::to_string(|s| {
2460+
use print::pprust::PrintState;
2461+
use print::pp::word;
2462+
s.popen()?;
2463+
s.print_expr(&e)?;
2464+
word(&mut s.s, ".")?;
2465+
s.print_usize(float.trunc() as usize)?;
2466+
s.pclose()?;
2467+
word(&mut s.s, ".")?;
2468+
word(&mut s.s, fstr.splitn(2, ".").last().unwrap())
2469+
});
2470+
err.span_suggestion(
2471+
prev_span,
2472+
"try parenthesizing the first index",
2473+
sugg);
24622474
}
24632475
return Err(err);
24642476

@@ -3900,7 +3912,14 @@ impl<'a> Parser<'a> {
39003912
if self.eat(&token::Semi) {
39013913
stmt_span.hi = self.prev_span.hi;
39023914
}
3903-
e.span_help(stmt_span, "try placing this code inside a block");
3915+
let sugg = pprust::to_string(|s| {
3916+
use print::pprust::{PrintState, INDENT_UNIT};
3917+
s.ibox(INDENT_UNIT)?;
3918+
s.bopen()?;
3919+
s.print_stmt(&stmt)?;
3920+
s.bclose_maybe_open(stmt.span, INDENT_UNIT, false)
3921+
});
3922+
e.span_suggestion(stmt_span, "try placing this code inside a block", sugg);
39043923
}
39053924
Err(mut e) => {
39063925
self.recover_stmt_(SemiColonMode::Break);

src/test/compile-fail/missing-block-hint.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn main() {
1515
{
1616
if (foo)
1717
bar; //~ ERROR expected `{`, found `bar`
18-
//^ HELP try placing this code inside a block
18+
//~^ HELP try placing this code inside a block
19+
//~| SUGGESTION { bar; }
1920
}
2021
}

src/test/parse-fail/tuple-float-index.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212

1313
fn main () {
1414
(1, (2, 3)).1.1; //~ ERROR unexpected token
15-
//~^ HELP try parenthesizing the first index; e.g., `(foo.1).1`
15+
//~^ HELP try parenthesizing the first index
16+
//~| SUGGESTION ((1, (2, 3)).1).1
1617
}

0 commit comments

Comments
 (0)