Rollup merge of #115473 - gurry:113110-expected-item, r=compiler-errors
Add explanatory note to 'expected item' error Fixes #113110 It changes the diagnostic from this: ``` error: expected item, found `5` --> ../test.rs:1:1 | 1 | 5 | ^ expected item ``` to this: ``` error: expected item, found `5` --> ../test.rs:1:1 | 1 | 5 | ^ expected item | = note: items are things that can appear at the root of a module = note: for a full list see https://doc.rust-lang.org/reference/items.html ```
This commit is contained in:
commit
4a31cc859b
14 changed files with 41 additions and 4 deletions
|
@ -73,12 +73,16 @@ impl<'a> Parser<'a> {
|
||||||
if !self.maybe_consume_incorrect_semicolon(&items) {
|
if !self.maybe_consume_incorrect_semicolon(&items) {
|
||||||
let msg = format!("expected item, found {token_str}");
|
let msg = format!("expected item, found {token_str}");
|
||||||
let mut err = self.struct_span_err(self.token.span, msg);
|
let mut err = self.struct_span_err(self.token.span, msg);
|
||||||
let label = if self.is_kw_followed_by_ident(kw::Let) {
|
let span = self.token.span;
|
||||||
"consider using `const` or `static` instead of `let` for global variables"
|
if self.is_kw_followed_by_ident(kw::Let) {
|
||||||
|
err.span_label(
|
||||||
|
span,
|
||||||
|
"consider using `const` or `static` instead of `let` for global variables",
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
"expected item"
|
err.span_label(span, "expected item")
|
||||||
|
.note("for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>");
|
||||||
};
|
};
|
||||||
err.span_label(self.token.span, label);
|
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ error: expected item, found keyword `pub`
|
||||||
|
|
|
|
||||||
LL | default pub const async unsafe extern fn err() {}
|
LL | default pub const async unsafe extern fn err() {}
|
||||||
| ^^^ expected item
|
| ^^^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ error: expected item, found reserved keyword `do`
|
||||||
|
|
|
|
||||||
LL | default do
|
LL | default do
|
||||||
| ^^ expected item
|
| ^^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ error: expected item, found keyword `unsafe`
|
||||||
|
|
|
|
||||||
LL | default unsafe FAIL
|
LL | default unsafe FAIL
|
||||||
| ^^^^^^ expected item
|
| ^^^^^^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ error: expected item, found `==`
|
||||||
|
|
|
|
||||||
LL | B == 2
|
LL | B == 2
|
||||||
| ^^ expected item
|
| ^^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
5 //~ ERROR expected item, found `5`
|
|
@ -0,0 +1,10 @@
|
||||||
|
error: expected item, found `5`
|
||||||
|
--> $DIR/issue-113110-non-item-at-module-root.rs:1:2
|
||||||
|
|
|
||||||
|
LL | 5
|
||||||
|
| ^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
|
@ -3,6 +3,8 @@ error: expected item, found keyword `where`
|
||||||
|
|
|
|
||||||
LL | struct Bar<T> { x: T } where T: Copy
|
LL | struct Bar<T> { x: T } where T: Copy
|
||||||
| ^^^^^ expected item
|
| ^^^^^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ error: expected item, found `|`
|
||||||
|
|
|
|
||||||
LL | |
|
LL | |
|
||||||
| ^ expected item
|
| ^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ error: expected item, found `"\u\"`
|
||||||
|
|
|
|
||||||
LL | "\u\"
|
LL | "\u\"
|
||||||
| ^^^^^^ expected item
|
| ^^^^^^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ error: expected item, found `)`
|
||||||
|
|
|
|
||||||
LL | enum e{A((?'a a+?+l))}
|
LL | enum e{A((?'a a+?+l))}
|
||||||
| ^ expected item
|
| ^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ error: expected item, found `[`
|
||||||
|
|
|
|
||||||
LL | [allow(unused_variables)]
|
LL | [allow(unused_variables)]
|
||||||
| ^ expected item
|
| ^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ error: expected item, found reserved keyword `virtual`
|
||||||
|
|
|
|
||||||
LL | virtual struct SuperStruct {
|
LL | virtual struct SuperStruct {
|
||||||
| ^^^^^^^ expected item
|
| ^^^^^^^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ error: expected item, found `(`
|
||||||
|
|
|
|
||||||
LL | pub(crate) () fn foo() {}
|
LL | pub(crate) () fn foo() {}
|
||||||
| ^ expected item
|
| ^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue