Remove anon struct and union types

This commit is contained in:
Michael Goulet 2024-09-29 22:17:30 -04:00
parent e3a0da1863
commit 40465d2449
19 changed files with 3 additions and 227 deletions

View file

@ -128,17 +128,6 @@ impl<'a> Parser<'a> {
)
}
/// Parse a type suitable for a field definition.
/// The difference from `parse_ty` is that this version
/// allows anonymous structs and unions.
pub(super) fn parse_ty_for_field_def(&mut self) -> PResult<'a, P<Ty>> {
if self.can_begin_anon_struct_or_union() {
self.parse_anon_struct_or_union()
} else {
self.parse_ty()
}
}
/// Parse a type suitable for a function or function pointer parameter.
/// The difference from `parse_ty` is that this version allows `...`
/// (`CVarArgs`) at the top level of the type.
@ -382,37 +371,6 @@ impl<'a> Parser<'a> {
if allow_qpath_recovery { self.maybe_recover_from_bad_qpath(ty) } else { Ok(ty) }
}
/// Parse an anonymous struct or union (only for field definitions):
/// ```ignore (feature-not-ready)
/// #[repr(C)]
/// struct Foo {
/// _: struct { // anonymous struct
/// x: u32,
/// y: f64,
/// }
/// _: union { // anonymous union
/// z: u32,
/// w: f64,
/// }
/// }
/// ```
fn parse_anon_struct_or_union(&mut self) -> PResult<'a, P<Ty>> {
assert!(self.token.is_keyword(kw::Union) || self.token.is_keyword(kw::Struct));
let is_union = self.token.is_keyword(kw::Union);
let lo = self.token.span;
self.bump();
let (fields, _recovered) =
self.parse_record_struct_body(if is_union { "union" } else { "struct" }, lo, false)?;
let span = lo.to(self.prev_token.span);
self.psess.gated_spans.gate(sym::unnamed_fields, span);
let id = ast::DUMMY_NODE_ID;
let kind =
if is_union { TyKind::AnonUnion(id, fields) } else { TyKind::AnonStruct(id, fields) };
Ok(self.mk_ty(span, kind))
}
/// Parses either:
/// - `(TYPE)`, a parenthesized type.
/// - `(TYPE,)`, a tuple with a single field of type TYPE.
@ -813,11 +771,6 @@ impl<'a> Parser<'a> {
Ok(bounds)
}
pub(super) fn can_begin_anon_struct_or_union(&mut self) -> bool {
(self.token.is_keyword(kw::Struct) || self.token.is_keyword(kw::Union))
&& self.look_ahead(1, |t| t == &token::OpenDelim(Delimiter::Brace))
}
/// Can the current token begin a bound?
fn can_begin_bound(&mut self) -> bool {
self.check_path()