expected.dedup();
let expect = tokens_to_string(&expected[..]);
let actual = self.this_token_to_string();
- Err(self.fatal(
- &(if expected.len() > 1 {
- (format!("expected one of {}, found `{}`",
- expect,
- actual))
- } else if expected.is_empty() {
- (format!("unexpected token: `{}`",
- actual))
- } else {
- (format!("expected {}, found `{}`",
- expect,
- actual))
- })[..]
- ))
+ let (msg_exp, label_exp) = if expected.len() > 1 {
+ (format!("expected one of {}, found `{}`", expect, actual),
+ format!("expected one of {} after this", expect))
+ } else if expected.is_empty() {
+ (format!("unexpected token: `{}`", actual),
+ "unexpected token after this".to_string())
+ } else {
+ (format!("expected {}, found `{}`", expect, actual),
+ format!("expected {} after this", expect))
+ };
+ let mut err = self.fatal(&msg_exp);
+ err.span_label(self.prev_span, &label_exp);
+ err.span_label(self.span, &"unexpected token");
+ Err(err)
}
}
pub fn trace_option(option: Option<isize>) {
option.map(|some| 42; //~ NOTE: unclosed delimiter
//~^ ERROR: expected one of
+ //~| NOTE: expected one of
+ //~| NOTE: unexpected token
} //~ ERROR: incorrect close delimiter
//~^ ERROR: expected expression, found `)`
macro_rules! ignored_expr {
() => ( 1, //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `,`
+ //~^ NOTE expected one of `.`, `;`, `?`, `}`, or an operator after this
+ //~| NOTE unexpected token
2 )
}
type A = Box<(Fn(D::Error) -> E) + 'static + Send + Sync>; // OK (but see #39318)
-FAIL //~ ERROR
+FAIL
+//~^ ERROR
+//~| ERROR
let foo =
match //~ NOTE did you mean to remove this `match` keyword?
Some(4).unwrap_or_else(5)
- ; //~ ERROR expected one of `.`, `?`, `{`, or an operator, found `;`
+ //~^ NOTE expected one of `.`, `?`, `{`, or an operator after this
+ ; //~ NOTE unexpected token
+ //~^ ERROR expected one of `.`, `?`, `{`, or an operator, found `;`
println!("{}", foo)
}
let x: Box<Debug+> = box 3 as Box<Debug+>; // Trailing `+` is OK
}
-FAIL //~ ERROR
+FAIL
+//~^ ERROR
+//~| ERROR
--> $DIR/token-error-correct-3.rs:23:35
|
23 | callback(path.as_ref(); //~ NOTE: unclosed delimiter
- | ^
+ | -^ unexpected token
+ | |
+ | expected one of `,`, `.`, `?`, or an operator after this
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
--> $DIR/token-error-correct-3.rs:29:9
|
+25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
+ | - expected one of `.`, `;`, `?`, `}`, or an operator after this
+...
29 | } else { //~ ERROR: incorrect close delimiter: `}`
- | ^
+ | ^ unexpected token
error[E0425]: cannot find function `is_directory` in this scope
--> $DIR/token-error-correct-3.rs:21:13
--> $DIR/token-error-correct.rs:14:13
|
14 | foo(bar(;
- | ^
+ | -^ unexpected token
+ | |
+ | expected one of `)`, `,`, `.`, `<`, `?`, `break`, `continue`, `false`, `for`, `if`, `loop`, `match`, `move`, `return`, `true`, `unsafe`, `while`, or an operator after this
error: expected expression, found `)`
--> $DIR/token-error-correct.rs:23:1