Skip to content

Commit 18a79e0

Browse files
authored
Rollup merge of #67078 - kamleshbhalui:master, r=Centril
accept union inside enum if not followed by identifier Fixes #66943
2 parents 459398d + f8ecf04 commit 18a79e0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/librustc_parse/parser/item.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1727,9 +1727,10 @@ impl<'a> Parser<'a> {
17271727
/// Checks if current token is one of tokens which cannot be nested like `kw::Enum`. In case
17281728
/// it is, we try to parse the item and report error about nested types.
17291729
fn recover_nested_adt_item(&mut self, keyword: Symbol) -> PResult<'a, bool> {
1730-
if self.token.is_keyword(kw::Enum) ||
1730+
if (self.token.is_keyword(kw::Enum) ||
17311731
self.token.is_keyword(kw::Struct) ||
1732-
self.token.is_keyword(kw::Union)
1732+
self.token.is_keyword(kw::Union))
1733+
&& self.look_ahead(1, |t| t.is_ident())
17331734
{
17341735
let kw_token = self.token.clone();
17351736
let kw_str = pprust::token_to_string(&kw_token);

src/test/ui/enum/union-in-enum.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This test checks that the union keyword
2+
// is accepted as the name of an enum variant
3+
// when not followed by an identifier
4+
// This special case exists because `union` is a contextual keyword.
5+
6+
#![allow(warnings)]
7+
8+
// check-pass
9+
10+
enum A { union }
11+
enum B { union {} }
12+
enum C { union() }
13+
fn main(){}

0 commit comments

Comments
 (0)