未验证 提交 18a79e0e 编写于 作者: M Mazdak Farrokhzad 提交者: GitHub

Rollup merge of #67078 - kamleshbhalui:master, r=Centril

accept union inside enum if not followed by identifier

Fixes #66943
......@@ -1727,9 +1727,10 @@ fn report_invalid_macro_expansion_item(&self) {
/// 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);
......
// 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(){}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册