Revert "Implement Anonymous{Struct, Union} in the AST"
This reverts commit059b68dd67
. Note that this was manually adjusted to retain some of the refactoring introduced by commit059b68dd67
, so that it could likewise retain the correction introduced in commit5b4bc05fa5
This commit is contained in:
parent
b6aa7e3105
commit
91feb76d13
13 changed files with 14 additions and 209 deletions
|
@ -1234,7 +1234,7 @@ impl<'a> Parser<'a> {
|
|||
Ok((class_name, ItemKind::Union(vdata, generics)))
|
||||
}
|
||||
|
||||
pub(super) fn parse_record_struct_body(
|
||||
fn parse_record_struct_body(
|
||||
&mut self,
|
||||
adt_ty: &str,
|
||||
) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> {
|
||||
|
@ -1468,28 +1468,19 @@ impl<'a> Parser<'a> {
|
|||
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
|
||||
let (ident, is_raw) = self.ident_or_err()?;
|
||||
if !is_raw && ident.is_reserved() {
|
||||
if ident.name == kw::Underscore {
|
||||
self.sess.gated_spans.gate(sym::unnamed_fields, lo);
|
||||
let err = if self.check_fn_front_matter(false) {
|
||||
let _ = self.parse_fn(&mut Vec::new(), |_| true, lo);
|
||||
let mut err = self.struct_span_err(
|
||||
lo.to(self.prev_token.span),
|
||||
&format!("functions are not allowed in {} definitions", adt_ty),
|
||||
);
|
||||
err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks");
|
||||
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
|
||||
err
|
||||
} else {
|
||||
let err = if self.check_fn_front_matter(false) {
|
||||
// We use `parse_fn` to get a span for the function
|
||||
if let Err(mut db) = self.parse_fn(&mut Vec::new(), |_| true, lo) {
|
||||
db.delay_as_bug();
|
||||
}
|
||||
let mut err = self.struct_span_err(
|
||||
lo.to(self.prev_token.span),
|
||||
&format!("functions are not allowed in {} definitions", adt_ty),
|
||||
);
|
||||
err.help(
|
||||
"unlike in C++, Java, and C#, functions are declared in `impl` blocks",
|
||||
);
|
||||
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
|
||||
err
|
||||
} else {
|
||||
self.expected_ident_found()
|
||||
};
|
||||
return Err(err);
|
||||
}
|
||||
self.expected_ident_found()
|
||||
};
|
||||
return Err(err);
|
||||
}
|
||||
self.bump();
|
||||
Ok(ident)
|
||||
|
|
|
@ -226,19 +226,6 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
} else if self.eat_keyword(kw::Impl) {
|
||||
self.parse_impl_ty(&mut impl_dyn_multi)?
|
||||
} else if self.token.is_keyword(kw::Union)
|
||||
&& self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))
|
||||
{
|
||||
self.bump();
|
||||
let (fields, recovered) = self.parse_record_struct_body("union")?;
|
||||
let span = lo.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::unnamed_fields, span);
|
||||
TyKind::AnonymousUnion(fields, recovered)
|
||||
} else if self.eat_keyword(kw::Struct) {
|
||||
let (fields, recovered) = self.parse_record_struct_body("struct")?;
|
||||
let span = lo.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::unnamed_fields, span);
|
||||
TyKind::AnonymousStruct(fields, recovered)
|
||||
} else if self.is_explicit_dyn_type() {
|
||||
self.parse_dyn_ty(&mut impl_dyn_multi)?
|
||||
} else if self.eat_lt() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue