diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 86991f047e46d..3dda370d25af3 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -228,8 +228,8 @@ impl<'a> Parser<'a> { body, define_opaque: None, })) - } else if self.eat_keyword(exp!(Extern)) { - if self.eat_keyword(exp!(Crate)) { + } else if self.eat_keyword_case(exp!(Extern), case) { + if self.eat_keyword_case(exp!(Crate), case) { // EXTERN CRATE self.parse_item_extern_crate()? } else { @@ -247,7 +247,7 @@ impl<'a> Parser<'a> { self.bump(); // `static` let mutability = self.parse_mutability(); self.parse_static_item(safety, mutability)? - } else if self.check_keyword(exp!(Trait)) || self.check_trait_front_matter() { + } else if self.check_keyword_case(exp!(Trait), case) || self.check_trait_front_matter() { // TRAIT ITEM self.parse_item_trait(attrs, lo)? } else if self.check_impl_frontmatter() { @@ -268,18 +268,18 @@ impl<'a> Parser<'a> { })) } else if self.is_reuse_path_item() { self.parse_item_delegation()? - } else if self.check_keyword(exp!(Mod)) - || self.check_keyword(exp!(Unsafe)) && self.is_keyword_ahead(1, &[kw::Mod]) + } else if self.check_keyword_case(exp!(Mod), case) + || self.check_keyword_case(exp!(Unsafe), case) && self.is_keyword_ahead(1, &[kw::Mod]) { // MODULE ITEM self.parse_item_mod(attrs)? - } else if self.eat_keyword(exp!(Type)) { + } else if self.eat_keyword_case(exp!(Type), case) { // TYPE ITEM self.parse_type_alias(def_())? - } else if self.eat_keyword(exp!(Enum)) { + } else if self.eat_keyword_case(exp!(Enum), case) { // ENUM ITEM self.parse_item_enum()? - } else if self.eat_keyword(exp!(Struct)) { + } else if self.eat_keyword_case(exp!(Struct), case) { // STRUCT ITEM self.parse_item_struct()? } else if self.is_kw_followed_by_ident(kw::Union) { @@ -289,7 +289,7 @@ impl<'a> Parser<'a> { } else if self.is_builtin() { // BUILTIN# ITEM return self.parse_item_builtin(); - } else if self.eat_keyword(exp!(Macro)) { + } else if self.eat_keyword_case(exp!(Macro), case) { // MACROS 2.0 ITEM self.parse_item_decl_macro(lo)? } else if let IsMacroRulesItem::Yes { has_bang } = self.is_macro_rules_item() { diff --git a/tests/ui/parser/misspelled-keywords/assoc-type.rs b/tests/ui/parser/misspelled-keywords/assoc-type.rs index a6b694a2abe6b..31328d010ae91 100644 --- a/tests/ui/parser/misspelled-keywords/assoc-type.rs +++ b/tests/ui/parser/misspelled-keywords/assoc-type.rs @@ -1,6 +1,8 @@ +#![feature(associated_type_defaults)] + trait Animal { Type Result = u8; - //~^ ERROR expected one of + //~^ ERROR keyword `type` is written in the wrong case } fn main() {} diff --git a/tests/ui/parser/misspelled-keywords/assoc-type.stderr b/tests/ui/parser/misspelled-keywords/assoc-type.stderr index e529b477c05bc..cb3c2ccd84cdc 100644 --- a/tests/ui/parser/misspelled-keywords/assoc-type.stderr +++ b/tests/ui/parser/misspelled-keywords/assoc-type.stderr @@ -1,15 +1,10 @@ -error: expected one of `!` or `::`, found `Result` - --> $DIR/assoc-type.rs:2:10 +error: keyword `type` is written in the wrong case + --> $DIR/assoc-type.rs:4:5 | -LL | trait Animal { - | - while parsing this item list starting here LL | Type Result = u8; - | ^^^^^^ expected one of `!` or `::` -LL | -LL | } - | - the item list ends here + | ^^^^ | -help: write keyword `type` in lowercase +help: write it in the correct case | LL - Type Result = u8; LL + type Result = u8; diff --git a/tests/ui/parser/misspelled-keywords/struct.rs b/tests/ui/parser/misspelled-keywords/struct.rs index 0f64dec6f56b3..b881003002fca 100644 --- a/tests/ui/parser/misspelled-keywords/struct.rs +++ b/tests/ui/parser/misspelled-keywords/struct.rs @@ -1,4 +1,7 @@ Struct Foor { -//~^ ERROR expected one of +//~^ ERROR keyword `struct` is written in the wrong case hello: String, } + +stuct Barr; +//~^ ERROR expected one of `!` or `::`, found `Barr` diff --git a/tests/ui/parser/misspelled-keywords/struct.stderr b/tests/ui/parser/misspelled-keywords/struct.stderr index af8614ef14b71..5b9e93a51d7b6 100644 --- a/tests/ui/parser/misspelled-keywords/struct.stderr +++ b/tests/ui/parser/misspelled-keywords/struct.stderr @@ -1,14 +1,25 @@ -error: expected one of `!` or `::`, found `Foor` - --> $DIR/struct.rs:1:8 +error: keyword `struct` is written in the wrong case + --> $DIR/struct.rs:1:1 | LL | Struct Foor { - | ^^^^ expected one of `!` or `::` + | ^^^^^^ | -help: write keyword `struct` in lowercase (notice the capitalization) +help: write it in the correct case (notice the capitalization) | LL - Struct Foor { LL + struct Foor { | -error: aborting due to 1 previous error +error: expected one of `!` or `::`, found `Barr` + --> $DIR/struct.rs:6:7 + | +LL | stuct Barr; + | ^^^^ expected one of `!` or `::` + | +help: there is a keyword `struct` with a similar name + | +LL | struct Barr; + | + + +error: aborting due to 2 previous errors