Parse unnamed fields and anonymous structs or unions
Anonymous structs or unions are only allowed in struct field definitions. Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
This commit is contained in:
parent
439d066bcf
commit
868706d9b5
25 changed files with 650 additions and 5 deletions
|
@ -1594,7 +1594,7 @@ impl<'a> Parser<'a> {
|
|||
Ok((class_name, ItemKind::Union(vdata, generics)))
|
||||
}
|
||||
|
||||
fn parse_record_struct_body(
|
||||
pub(crate) fn parse_record_struct_body(
|
||||
&mut self,
|
||||
adt_ty: &str,
|
||||
ident_span: Span,
|
||||
|
@ -1869,7 +1869,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
self.expect_field_ty_separator()?;
|
||||
let ty = self.parse_ty()?;
|
||||
let ty = self.parse_ty_for_field_def()?;
|
||||
if self.token.kind == token::Colon && self.look_ahead(1, |tok| tok.kind != token::Colon) {
|
||||
self.sess.emit_err(errors::SingleColonStructType { span: self.token.span });
|
||||
}
|
||||
|
@ -1894,7 +1894,9 @@ impl<'a> Parser<'a> {
|
|||
/// for better diagnostics and suggestions.
|
||||
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
|
||||
let (ident, is_raw) = self.ident_or_err(true)?;
|
||||
if !is_raw && ident.is_reserved() {
|
||||
if ident.name == kw::Underscore {
|
||||
self.sess.gated_spans.gate(sym::unnamed_fields, lo);
|
||||
} else if !is_raw && ident.is_reserved() {
|
||||
let snapshot = self.create_snapshot_for_diagnostic();
|
||||
let err = if self.check_fn_front_matter(false, Case::Sensitive) {
|
||||
let inherited_vis = Visibility {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue