Skip to content

Commit 82965ff

Browse files
committed
Recover on misspelled item keyword
1 parent 85e24b0 commit 82965ff

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed

compiler/rustc_parse/src/parser/item.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ impl<'a> Parser<'a> {
228228
body,
229229
define_opaque: None,
230230
}))
231-
} else if self.eat_keyword(exp!(Extern)) {
232-
if self.eat_keyword(exp!(Crate)) {
231+
} else if self.eat_keyword_case(exp!(Extern), case) {
232+
if self.eat_keyword_case(exp!(Crate), case) {
233233
// EXTERN CRATE
234234
self.parse_item_extern_crate()?
235235
} else {
@@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
247247
self.bump(); // `static`
248248
let mutability = self.parse_mutability();
249249
self.parse_static_item(safety, mutability)?
250-
} else if self.check_keyword(exp!(Trait)) || self.check_trait_front_matter() {
250+
} else if self.check_keyword_case(exp!(Trait), case) || self.check_trait_front_matter() {
251251
// TRAIT ITEM
252252
self.parse_item_trait(attrs, lo)?
253253
} else if self.check_impl_frontmatter() {
@@ -268,18 +268,18 @@ impl<'a> Parser<'a> {
268268
}))
269269
} else if self.is_reuse_path_item() {
270270
self.parse_item_delegation()?
271-
} else if self.check_keyword(exp!(Mod))
272-
|| self.check_keyword(exp!(Unsafe)) && self.is_keyword_ahead(1, &[kw::Mod])
271+
} else if self.check_keyword_case(exp!(Mod), case)
272+
|| self.check_keyword_case(exp!(Unsafe), case) && self.is_keyword_ahead(1, &[kw::Mod])
273273
{
274274
// MODULE ITEM
275275
self.parse_item_mod(attrs)?
276-
} else if self.eat_keyword(exp!(Type)) {
276+
} else if self.eat_keyword_case(exp!(Type), case) {
277277
// TYPE ITEM
278278
self.parse_type_alias(def_())?
279-
} else if self.eat_keyword(exp!(Enum)) {
279+
} else if self.eat_keyword_case(exp!(Enum), case) {
280280
// ENUM ITEM
281281
self.parse_item_enum()?
282-
} else if self.eat_keyword(exp!(Struct)) {
282+
} else if self.eat_keyword_case(exp!(Struct), case) {
283283
// STRUCT ITEM
284284
self.parse_item_struct()?
285285
} else if self.is_kw_followed_by_ident(kw::Union) {
@@ -289,7 +289,7 @@ impl<'a> Parser<'a> {
289289
} else if self.is_builtin() {
290290
// BUILTIN# ITEM
291291
return self.parse_item_builtin();
292-
} else if self.eat_keyword(exp!(Macro)) {
292+
} else if self.eat_keyword_case(exp!(Macro), case) {
293293
// MACROS 2.0 ITEM
294294
self.parse_item_decl_macro(lo)?
295295
} else if let IsMacroRulesItem::Yes { has_bang } = self.is_macro_rules_item() {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#![feature(associated_type_defaults)]
2+
13
trait Animal {
24
Type Result = u8;
3-
//~^ ERROR expected one of
5+
//~^ ERROR keyword `type` is written in the wrong case
46
}
57

68
fn main() {}

tests/ui/parser/misspelled-keywords/assoc-type.stderr

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
error: expected one of `!` or `::`, found `Result`
2-
--> $DIR/assoc-type.rs:2:10
1+
error: keyword `type` is written in the wrong case
2+
--> $DIR/assoc-type.rs:4:5
33
|
4-
LL | trait Animal {
5-
| - while parsing this item list starting here
64
LL | Type Result = u8;
7-
| ^^^^^^ expected one of `!` or `::`
8-
LL |
9-
LL | }
10-
| - the item list ends here
5+
| ^^^^
116
|
12-
help: write keyword `type` in lowercase
7+
help: write it in lowercase
138
|
149
LL - Type Result = u8;
1510
LL + type Result = u8;
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Struct Foor {
2-
//~^ ERROR expected one of
2+
//~^ ERROR keyword `struct` is written in the wrong case
33
hello: String,
44
}
5+
6+
stuct Barr;
7+
//~^ ERROR expected one of `!` or `::`, found `Barr`
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
error: expected one of `!` or `::`, found `Foor`
2-
--> $DIR/struct.rs:1:8
1+
error: keyword `struct` is written in the wrong case
2+
--> $DIR/struct.rs:1:1
33
|
44
LL | Struct Foor {
5-
| ^^^^ expected one of `!` or `::`
5+
| ^^^^^^
66
|
7-
help: write keyword `struct` in lowercase (notice the capitalization)
7+
help: write it in lowercase (notice the capitalization)
88
|
99
LL - Struct Foor {
1010
LL + struct Foor {
1111
|
1212

13-
error: aborting due to 1 previous error
13+
error: expected one of `!` or `::`, found `Barr`
14+
--> $DIR/struct.rs:6:7
15+
|
16+
LL | stuct Barr;
17+
| ^^^^ expected one of `!` or `::`
18+
|
19+
help: there is a keyword `struct` with a similar name
20+
|
21+
LL | struct Barr;
22+
| +
23+
24+
error: aborting due to 2 previous errors
1425

0 commit comments

Comments
 (0)