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) {
|
||||
let msg = format!("expected item, found {token_str}");
|
||||
let mut err = self.struct_span_err(self.token.span, msg);
|
||||
let label = if self.is_kw_followed_by_ident(kw::Let) {
|
||||
"consider using `const` or `static` instead of `let` for global variables"
|
||||
let span = self.token.span;
|
||||
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 {
|
||||
"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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue