diff options
| author | Kamlesh Kumar <kamleshbhalui@gmail.com> | 2019-12-06 10:52:28 +0530 |
|---|---|---|
| committer | Kamlesh Kumar <kamleshbhalui@gmail.com> | 2019-12-06 10:52:28 +0530 |
| commit | f8ecf04f4b60f1004b9ba4092747f16d290dfff7 (patch) | |
| tree | 225d0d5ad73d4b07b3131cf1fd112411e5916fb2 | |
| parent | 234c9f21d9930e4ae804d00b191d0780959cfcbe (diff) | |
| download | rust-f8ecf04f4b60f1004b9ba4092747f16d290dfff7.tar.gz rust-f8ecf04f4b60f1004b9ba4092747f16d290dfff7.zip | |
accept union inside enum if not followed by identifier
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/enum/union-in-enum.rs | 13 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index ccf78e6402b..c3e5b39635f 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -1727,9 +1727,10 @@ impl<'a> Parser<'a> { /// Checks if current token is one of tokens which cannot be nested like `kw::Enum`. In case /// it is, we try to parse the item and report error about nested types. fn recover_nested_adt_item(&mut self, keyword: Symbol) -> PResult<'a, bool> { - if self.token.is_keyword(kw::Enum) || + if (self.token.is_keyword(kw::Enum) || self.token.is_keyword(kw::Struct) || - self.token.is_keyword(kw::Union) + self.token.is_keyword(kw::Union)) + && self.look_ahead(1, |t| t.is_ident()) { let kw_token = self.token.clone(); let kw_str = pprust::token_to_string(&kw_token); diff --git a/src/test/ui/enum/union-in-enum.rs b/src/test/ui/enum/union-in-enum.rs new file mode 100644 index 00000000000..048913e25cd --- /dev/null +++ b/src/test/ui/enum/union-in-enum.rs @@ -0,0 +1,13 @@ +// This test checks that the union keyword +// is accepted as the name of an enum variant +// when not followed by an identifier +// This special case exists because `union` is a contextual keyword. + +#![allow(warnings)] + +// check-pass + +enum A { union } +enum B { union {} } +enum C { union() } +fn main(){} |
