Skip to content

Commit

Permalink
Rollup merge of rust-lang#67078 - kamleshbhalui:master, r=Centril
Browse files Browse the repository at this point in the history
accept union inside enum if not followed by identifier

Fixes rust-lang#66943
  • Loading branch information
Centril authored Dec 6, 2019
2 parents 459398d + f8ecf04 commit 18a79e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/enum/union-in-enum.rs
Original file line number Diff line number Diff line change
@@ -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(){}

0 comments on commit 18a79e0

Please sign in to comment.