mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
Use token description in "expected/found" parse messages
This commit is contained in:
parent
3e6f30ec3e
commit
3e22e0c3bc
@ -611,6 +611,7 @@ impl<'a> Parser<'a> {
|
||||
t if t.is_special_ident() => "reserved identifier",
|
||||
t if t.is_used_keyword() => "keyword",
|
||||
t if t.is_unused_keyword() => "reserved keyword",
|
||||
token::DocComment(..) => "doc comment",
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@ -644,8 +645,8 @@ impl<'a> Parser<'a> {
|
||||
Ok(())
|
||||
} else {
|
||||
let token_str = pprust::token_to_string(t);
|
||||
let this_token_str = self.this_token_to_string();
|
||||
let mut err = self.fatal(&format!("expected `{}`, found `{}`",
|
||||
let this_token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!("expected `{}`, found {}",
|
||||
token_str,
|
||||
this_token_str));
|
||||
|
||||
@ -1444,8 +1445,8 @@ impl<'a> Parser<'a> {
|
||||
Some(body)
|
||||
}
|
||||
_ => {
|
||||
let token_str = self.this_token_to_string();
|
||||
let mut err = self.fatal(&format!("expected `;` or `{{`, found `{}`",
|
||||
let token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!("expected `;` or `{{`, found {}",
|
||||
token_str));
|
||||
err.span_label(self.span, "expected `;` or `{`");
|
||||
return Err(err);
|
||||
@ -1453,8 +1454,8 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let token_str = self.this_token_to_string();
|
||||
let mut err = self.fatal(&format!("expected `;` or `{{`, found `{}`",
|
||||
let token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!("expected `;` or `{{`, found {}",
|
||||
token_str));
|
||||
err.span_label(self.span, "expected `;` or `{`");
|
||||
return Err(err);
|
||||
@ -3917,8 +3918,8 @@ impl<'a> Parser<'a> {
|
||||
etc_span = Some(etc_sp);
|
||||
break;
|
||||
}
|
||||
let token_str = self.this_token_to_string();
|
||||
let mut err = self.fatal(&format!("expected `}}`, found `{}`", token_str));
|
||||
let token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!("expected `}}`, found {}", token_str));
|
||||
|
||||
err.span_label(self.span, "expected `}`");
|
||||
let mut comma_sp = None;
|
||||
@ -4680,8 +4681,8 @@ impl<'a> Parser<'a> {
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let tok_str = self.this_token_to_string();
|
||||
let mut err = self.fatal(&format!("expected {}`(` or `{{`, found `{}`",
|
||||
let tok_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!("expected {}`(` or `{{`, found {}",
|
||||
ident_str,
|
||||
tok_str));
|
||||
err.span_label(self.span, format!("expected {}`(` or `{{`", ident_str));
|
||||
@ -4817,8 +4818,8 @@ impl<'a> Parser<'a> {
|
||||
|
||||
if !self.eat(&token::OpenDelim(token::Brace)) {
|
||||
let sp = self.span;
|
||||
let tok = self.this_token_to_string();
|
||||
let mut e = self.span_fatal(sp, &format!("expected `{{`, found `{}`", tok));
|
||||
let tok = self.this_token_descr();
|
||||
let mut e = self.span_fatal(sp, &format!("expected `{{`, found {}", tok));
|
||||
let do_not_suggest_help =
|
||||
self.token.is_keyword(keywords::In) || self.token == token::Colon;
|
||||
|
||||
@ -4880,6 +4881,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
e.span_label(sp, "expected `{`");
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
@ -4975,7 +4977,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn warn_missing_semicolon(&self) {
|
||||
self.diagnostic().struct_span_warn(self.span, {
|
||||
&format!("expected `;`, found `{}`", self.this_token_to_string())
|
||||
&format!("expected `;`, found {}", self.this_token_descr())
|
||||
}).note({
|
||||
"This was erroneously allowed and will become a hard error in a future release"
|
||||
}).emit();
|
||||
@ -6014,9 +6016,9 @@ impl<'a> Parser<'a> {
|
||||
self.expect(&token::Semi)?;
|
||||
body
|
||||
} else {
|
||||
let token_str = self.this_token_to_string();
|
||||
let token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!(
|
||||
"expected `where`, `{{`, `(`, or `;` after struct name, found `{}`",
|
||||
"expected `where`, `{{`, `(`, or `;` after struct name, found {}",
|
||||
token_str
|
||||
));
|
||||
err.span_label(self.span, "expected `where`, `{`, `(`, or `;` after struct name");
|
||||
@ -6038,9 +6040,9 @@ impl<'a> Parser<'a> {
|
||||
} else if self.token == token::OpenDelim(token::Brace) {
|
||||
VariantData::Struct(self.parse_record_struct_body()?, ast::DUMMY_NODE_ID)
|
||||
} else {
|
||||
let token_str = self.this_token_to_string();
|
||||
let token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!(
|
||||
"expected `where` or `{{` after union name, found `{}`", token_str));
|
||||
"expected `where` or `{{` after union name, found {}", token_str));
|
||||
err.span_label(self.span, "expected `where` or `{` after union name");
|
||||
return Err(err);
|
||||
};
|
||||
@ -6088,9 +6090,9 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
self.eat(&token::CloseDelim(token::Brace));
|
||||
} else {
|
||||
let token_str = self.this_token_to_string();
|
||||
let token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!(
|
||||
"expected `where`, or `{{` after struct name, found `{}`", token_str));
|
||||
"expected `where`, or `{{` after struct name, found {}", token_str));
|
||||
err.span_label(self.span, "expected `where`, or `{` after struct name");
|
||||
return Err(err);
|
||||
}
|
||||
@ -6166,8 +6168,8 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
_ => {
|
||||
let sp = self.sess.source_map().next_point(self.prev_span);
|
||||
let mut err = self.struct_span_err(sp, &format!("expected `,`, or `}}`, found `{}`",
|
||||
self.this_token_to_string()));
|
||||
let mut err = self.struct_span_err(sp, &format!("expected `,`, or `}}`, found {}",
|
||||
self.this_token_descr()));
|
||||
if self.token.is_ident() {
|
||||
// This is likely another field; emit the diagnostic and keep going
|
||||
err.span_suggestion_with_applicability(
|
||||
@ -6303,8 +6305,8 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
if !self.eat(term) {
|
||||
let token_str = self.this_token_to_string();
|
||||
let mut err = self.fatal(&format!("expected item, found `{}`", token_str));
|
||||
let token_str = self.this_token_descr();
|
||||
let mut err = self.fatal(&format!("expected item, found {}", token_str));
|
||||
if token_str == ";" {
|
||||
let msg = "consider removing this semicolon";
|
||||
err.span_suggestion_short_with_applicability(
|
||||
|
@ -28,7 +28,7 @@ error: expected `{`, found `;`
|
||||
LL | if not // lack of braces is [sic]
|
||||
| -- this `if` statement has a condition, but no block
|
||||
LL | println!("Then when?");
|
||||
| ^
|
||||
| ^ expected `{`
|
||||
|
||||
error: unexpected `2` after identifier
|
||||
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:36:24
|
||||
|
@ -16,3 +16,4 @@ fn main() {
|
||||
}
|
||||
}
|
||||
//~^ ERROR expected `{`, found `}`
|
||||
//~| NOTE expected `{`
|
||||
|
@ -5,7 +5,7 @@ LL | if 5 == {
|
||||
| -- this `if` statement has a condition, but no block
|
||||
...
|
||||
LL | }
|
||||
| ^
|
||||
| ^ expected `{`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: expected `{`, found `in`
|
||||
error: expected `{`, found keyword `in`
|
||||
--> $DIR/issue-51602.rs:12:10
|
||||
|
|
||||
LL | if i in 1..10 {
|
||||
|
@ -7,7 +7,7 @@ LL | if $tgt.has_$field() {}
|
||||
| this `if` statement has a condition, but no block
|
||||
...
|
||||
LL | get_opt!(bar, foo);
|
||||
| ^^^
|
||||
| ^^^ expected `{`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,9 +2,7 @@ error: expected item, found `;`
|
||||
--> $DIR/issue-46186.rs:13:2
|
||||
|
|
||||
LL | }; //~ ERROR expected item, found `;`
|
||||
| ^ help: consider removing this semicolon
|
||||
|
|
||||
= help: braced struct declarations are not followed by a semicolon
|
||||
| ^ expected item
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,7 +2,7 @@ error: expected item, found `;`
|
||||
--> $DIR/issue-49040.rs:11:28
|
||||
|
|
||||
LL | #![allow(unused_variables)]; //~ ERROR expected item, found `;`
|
||||
| ^ help: consider removing this semicolon
|
||||
| ^ expected item
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -10,6 +10,7 @@ error: expected `{`, found `'b`
|
||||
LL | if true 'b: {} //~ ERROR expected `{`, found `'b`
|
||||
| -- ^^----
|
||||
| | |
|
||||
| | expected `{`
|
||||
| | help: try placing this code inside a block: `{ 'b: { } }`
|
||||
| this `if` statement has a condition, but no block
|
||||
|
||||
@ -19,6 +20,7 @@ error: expected `{`, found `'b`
|
||||
LL | if true {} else 'b: {} //~ ERROR expected `{`, found `'b`
|
||||
| ^^----
|
||||
| |
|
||||
| expected `{`
|
||||
| help: try placing this code inside a block: `{ 'b: { } }`
|
||||
|
||||
error: expected one of `.`, `?`, `{`, or an operator, found `'b`
|
||||
|
@ -2,7 +2,7 @@ error: expected `{`, found `=>`
|
||||
--> $DIR/missing-block-hint.rs:13:18
|
||||
|
|
||||
LL | if (foo) => {} //~ ERROR expected `{`, found `=>`
|
||||
| -- ^^
|
||||
| -- ^^ expected `{`
|
||||
| |
|
||||
| this `if` statement has a condition, but no block
|
||||
|
||||
@ -14,6 +14,7 @@ LL | if (foo)
|
||||
LL | bar; //~ ERROR expected `{`, found `bar`
|
||||
| ^^^-
|
||||
| |
|
||||
| expected `{`
|
||||
| help: try placing this code inside a block: `{ bar; }`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
@ -1,4 +1,4 @@
|
||||
warning: expected `;`, found `let`
|
||||
warning: expected `;`, found keyword `let`
|
||||
--> $DIR/missing-semicolon-warning.rs:16:12
|
||||
|
|
||||
LL | $( let x = $e1 )*; //~ WARN expected `;`
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
fn /// document
|
||||
foo() {}
|
||||
//~^^ ERROR expected identifier, found `/// document`
|
||||
//~^^ ERROR expected identifier, found doc comment `/// document`
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected identifier, found `/// document`
|
||||
error: expected identifier, found doc comment `/// document`
|
||||
--> $DIR/doc-before-identifier.rs:13:4
|
||||
|
|
||||
LL | fn /// document
|
||||
| ^^^^^^^^^^^^ expected identifier
|
||||
| ^^^^^^^^^^^^ expected identifier, found doc comment
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
4
src/test/ui/parser/doc-comment-in-if-statement.rs
Normal file
4
src/test/ui/parser/doc-comment-in-if-statement.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
if true /*!*/ {}
|
||||
//~^ ERROR expected `{`, found doc comment `/*!*/`
|
||||
}
|
10
src/test/ui/parser/doc-comment-in-if-statement.stderr
Normal file
10
src/test/ui/parser/doc-comment-in-if-statement.stderr
Normal file
@ -0,0 +1,10 @@
|
||||
error: expected `{`, found doc comment `/*!*/`
|
||||
--> $DIR/doc-comment-in-if-statement.rs:2:13
|
||||
|
|
||||
LL | if true /*!*/ {}
|
||||
| -- ^^^^^ expected `{`
|
||||
| |
|
||||
| this `if` statement has a condition, but no block
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: expected `;`, found `as`
|
||||
error: expected `;`, found keyword `as`
|
||||
--> $DIR/import-from-rename.rs:15:16
|
||||
|
|
||||
LL | use foo::{bar} as baz;
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: expected `;`, found `as`
|
||||
error: expected `;`, found keyword `as`
|
||||
--> $DIR/import-glob-rename.rs:15:12
|
||||
|
|
||||
LL | use foo::* as baz;
|
||||
|
@ -10,6 +10,6 @@
|
||||
|
||||
// compile-flags: -Z parse-only -Z continue-parse-after-error
|
||||
|
||||
struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found `where`
|
||||
struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found keyword `where`
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,7 +1,7 @@
|
||||
error: expected item, found `where`
|
||||
error: expected item, found keyword `where`
|
||||
--> $DIR/issue-17904-2.rs:13:24
|
||||
|
|
||||
LL | struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found `where`
|
||||
LL | struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found keyword `where`
|
||||
| ^^^^^ expected item
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -12,7 +12,8 @@
|
||||
|
||||
// Test syntax checks for `type` keyword.
|
||||
|
||||
struct S1 for type; //~ ERROR expected `where`, `{`, `(`, or `;` after struct name, found `for`
|
||||
struct S1 for type;
|
||||
//~^ ERROR expected `where`, `{`, `(`, or `;` after struct name, found keyword `for`
|
||||
|
||||
pub fn main() {
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
error: expected `where`, `{`, `(`, or `;` after struct name, found `for`
|
||||
error: expected `where`, `{`, `(`, or `;` after struct name, found keyword `for`
|
||||
--> $DIR/unsized.rs:15:11
|
||||
|
|
||||
LL | struct S1 for type; //~ ERROR expected `where`, `{`, `(`, or `;` after struct name, found `for`
|
||||
LL | struct S1 for type;
|
||||
| ^^^ expected `where`, `{`, `(`, or `;` after struct name
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -12,7 +12,8 @@
|
||||
|
||||
// Test diagnostics for the removed struct inheritance feature.
|
||||
|
||||
virtual struct SuperStruct { //~ ERROR expected item, found `virtual`
|
||||
virtual struct SuperStruct {
|
||||
//~^ ERROR expected item, found reserved keyword `virtual`
|
||||
f1: isize,
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
error: expected item, found `virtual`
|
||||
error: expected item, found reserved keyword `virtual`
|
||||
--> $DIR/virtual-structs.rs:15:1
|
||||
|
|
||||
LL | virtual struct SuperStruct { //~ ERROR expected item, found `virtual`
|
||||
LL | virtual struct SuperStruct {
|
||||
| ^^^^^^^ expected item
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user