Auto merge of #60732 - jswrenn:arbitrary_enum_discriminant, r=pnkfelix
Implement arbitrary_enum_discriminant Implements RFC rust-lang/rfcs#2363 (tracking issue #60553).
This commit is contained in:
commit
303f77ee1d
18 changed files with 328 additions and 55 deletions
|
@ -6946,36 +6946,34 @@ impl<'a> Parser<'a> {
|
|||
/// Parses the part of an enum declaration following the `{`.
|
||||
fn parse_enum_def(&mut self, _generics: &ast::Generics) -> PResult<'a, EnumDef> {
|
||||
let mut variants = Vec::new();
|
||||
let mut any_disr = vec![];
|
||||
while self.token != token::CloseDelim(token::Brace) {
|
||||
let variant_attrs = self.parse_outer_attributes()?;
|
||||
let vlo = self.token.span;
|
||||
|
||||
let struct_def;
|
||||
let mut disr_expr = None;
|
||||
self.eat_bad_pub();
|
||||
let ident = self.parse_ident()?;
|
||||
if self.check(&token::OpenDelim(token::Brace)) {
|
||||
|
||||
let struct_def = if self.check(&token::OpenDelim(token::Brace)) {
|
||||
// Parse a struct variant.
|
||||
let (fields, recovered) = self.parse_record_struct_body()?;
|
||||
struct_def = VariantData::Struct(fields, recovered);
|
||||
VariantData::Struct(fields, recovered)
|
||||
} else if self.check(&token::OpenDelim(token::Paren)) {
|
||||
struct_def = VariantData::Tuple(
|
||||
VariantData::Tuple(
|
||||
self.parse_tuple_struct_body()?,
|
||||
ast::DUMMY_NODE_ID,
|
||||
);
|
||||
} else if self.eat(&token::Eq) {
|
||||
disr_expr = Some(AnonConst {
|
||||
)
|
||||
} else {
|
||||
VariantData::Unit(ast::DUMMY_NODE_ID)
|
||||
};
|
||||
|
||||
let disr_expr = if self.eat(&token::Eq) {
|
||||
Some(AnonConst {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
value: self.parse_expr()?,
|
||||
});
|
||||
if let Some(sp) = disr_expr.as_ref().map(|c| c.value.span) {
|
||||
any_disr.push(sp);
|
||||
}
|
||||
struct_def = VariantData::Unit(ast::DUMMY_NODE_ID);
|
||||
})
|
||||
} else {
|
||||
struct_def = VariantData::Unit(ast::DUMMY_NODE_ID);
|
||||
}
|
||||
None
|
||||
};
|
||||
|
||||
let vr = ast::Variant_ {
|
||||
ident,
|
||||
|
@ -7003,7 +7001,6 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
self.expect(&token::CloseDelim(token::Brace))?;
|
||||
self.maybe_report_invalid_custom_discriminants(any_disr, &variants);
|
||||
|
||||
Ok(ast::EnumDef { variants })
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue