Skip to content

Commit 91feb76

Browse files
committed
Revert "Implement Anonymous{Struct, Union} in the AST"
This reverts commit 059b68d. Note that this was manually adjusted to retain some of the refactoring introduced by commit 059b68d, so that it could likewise retain the correction introduced in commit 5b4bc05
1 parent b6aa7e3 commit 91feb76

File tree

13 files changed

+14
-209
lines changed

13 files changed

+14
-209
lines changed

compiler/rustc_ast/src/ast.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1902,10 +1902,6 @@ pub enum TyKind {
19021902
Never,
19031903
/// A tuple (`(A, B, C, D,...)`).
19041904
Tup(Vec<P<Ty>>),
1905-
/// An anonymous struct type i.e. `struct { foo: Type }`
1906-
AnonymousStruct(Vec<FieldDef>, bool),
1907-
/// An anonymous union type i.e. `union { bar: Type }`
1908-
AnonymousUnion(Vec<FieldDef>, bool),
19091905
/// A path (`module::module::...::Type`), optionally
19101906
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
19111907
///

compiler/rustc_ast/src/mut_visit.rs

-3
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,6 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
484484
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
485485
}
486486
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
487-
TyKind::AnonymousStruct(fields, ..) | TyKind::AnonymousUnion(fields, ..) => {
488-
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
489-
}
490487
}
491488
vis.visit_span(span);
492489
visit_lazy_tts(tokens, vis);

compiler/rustc_ast/src/visit.rs

-3
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,6 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
407407
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
408408
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
409409
TyKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
410-
TyKind::AnonymousStruct(ref fields, ..) | TyKind::AnonymousUnion(ref fields, ..) => {
411-
walk_list!(visitor, visit_field_def, fields)
412-
}
413410
TyKind::Never | TyKind::CVarArgs => {}
414411
}
415412
}

compiler/rustc_ast_lowering/src/item.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
748748
}
749749
}
750750

751-
pub(super) fn lower_field_def(
752-
&mut self,
753-
(index, f): (usize, &FieldDef),
754-
) -> hir::FieldDef<'hir> {
751+
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
755752
let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind {
756753
let t = self.lower_path_ty(
757754
&f.ty,

compiler/rustc_ast_lowering/src/lib.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1289,15 +1289,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12891289
let kind = match t.kind {
12901290
TyKind::Infer => hir::TyKind::Infer,
12911291
TyKind::Err => hir::TyKind::Err,
1292-
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1293-
TyKind::AnonymousStruct(ref _fields, _recovered) => {
1294-
self.sess.struct_span_err(t.span, "anonymous structs are unimplemented").emit();
1295-
hir::TyKind::Err
1296-
}
1297-
TyKind::AnonymousUnion(ref _fields, _recovered) => {
1298-
self.sess.struct_span_err(t.span, "anonymous unions are unimplemented").emit();
1299-
hir::TyKind::Err
1300-
}
13011292
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
13021293
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
13031294
TyKind::Rptr(ref region, ref mt) => {

compiler/rustc_ast_passes/src/feature_gate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
668668
// involved, so we only emit errors where there are no other parsing errors.
669669
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
670670
}
671-
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");
672671

673672
// All uses of `gate_all!` below this point were added in #65742,
674673
// and subsequently disabled (with the non-early gating readded).

compiler/rustc_ast_pretty/src/pprust/state.rs

-8
Original file line numberDiff line numberDiff line change
@@ -985,14 +985,6 @@ impl<'a> State<'a> {
985985
}
986986
self.pclose();
987987
}
988-
ast::TyKind::AnonymousStruct(ref fields, ..) => {
989-
self.s.word("struct");
990-
self.print_record_struct_body(fields, ty.span);
991-
}
992-
ast::TyKind::AnonymousUnion(ref fields, ..) => {
993-
self.s.word("union");
994-
self.print_record_struct_body(fields, ty.span);
995-
}
996988
ast::TyKind::Paren(ref typ) => {
997989
self.popen();
998990
self.print_type(typ);

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,6 @@ declare_features! (
639639
/// Allows specifying the as-needed link modifier
640640
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),
641641

642-
/// Allows unnamed fields of struct and union type
643-
(incomplete, unnamed_fields, "1.53.0", Some(49804), None),
644-
645642
/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
646643
(active, more_qualified_paths, "1.54.0", Some(86935), None),
647644

compiler/rustc_parse/src/parser/item.rs

+13-22
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ impl<'a> Parser<'a> {
12341234
Ok((class_name, ItemKind::Union(vdata, generics)))
12351235
}
12361236

1237-
pub(super) fn parse_record_struct_body(
1237+
fn parse_record_struct_body(
12381238
&mut self,
12391239
adt_ty: &str,
12401240
) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> {
@@ -1468,28 +1468,19 @@ impl<'a> Parser<'a> {
14681468
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
14691469
let (ident, is_raw) = self.ident_or_err()?;
14701470
if !is_raw && ident.is_reserved() {
1471-
if ident.name == kw::Underscore {
1472-
self.sess.gated_spans.gate(sym::unnamed_fields, lo);
1471+
let err = if self.check_fn_front_matter(false) {
1472+
let _ = self.parse_fn(&mut Vec::new(), |_| true, lo);
1473+
let mut err = self.struct_span_err(
1474+
lo.to(self.prev_token.span),
1475+
&format!("functions are not allowed in {} definitions", adt_ty),
1476+
);
1477+
err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks");
1478+
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
1479+
err
14731480
} else {
1474-
let err = if self.check_fn_front_matter(false) {
1475-
// We use `parse_fn` to get a span for the function
1476-
if let Err(mut db) = self.parse_fn(&mut Vec::new(), |_| true, lo) {
1477-
db.delay_as_bug();
1478-
}
1479-
let mut err = self.struct_span_err(
1480-
lo.to(self.prev_token.span),
1481-
&format!("functions are not allowed in {} definitions", adt_ty),
1482-
);
1483-
err.help(
1484-
"unlike in C++, Java, and C#, functions are declared in `impl` blocks",
1485-
);
1486-
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
1487-
err
1488-
} else {
1489-
self.expected_ident_found()
1490-
};
1491-
return Err(err);
1492-
}
1481+
self.expected_ident_found()
1482+
};
1483+
return Err(err);
14931484
}
14941485
self.bump();
14951486
Ok(ident)

compiler/rustc_parse/src/parser/ty.rs

-13
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,6 @@ impl<'a> Parser<'a> {
226226
}
227227
} else if self.eat_keyword(kw::Impl) {
228228
self.parse_impl_ty(&mut impl_dyn_multi)?
229-
} else if self.token.is_keyword(kw::Union)
230-
&& self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))
231-
{
232-
self.bump();
233-
let (fields, recovered) = self.parse_record_struct_body("union")?;
234-
let span = lo.to(self.prev_token.span);
235-
self.sess.gated_spans.gate(sym::unnamed_fields, span);
236-
TyKind::AnonymousUnion(fields, recovered)
237-
} else if self.eat_keyword(kw::Struct) {
238-
let (fields, recovered) = self.parse_record_struct_body("struct")?;
239-
let span = lo.to(self.prev_token.span);
240-
self.sess.gated_spans.gate(sym::unnamed_fields, span);
241-
TyKind::AnonymousStruct(fields, recovered)
242229
} else if self.is_explicit_dyn_type() {
243230
self.parse_dyn_ty(&mut impl_dyn_multi)?
244231
} else if self.eat_lt() {

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,6 @@ symbols! {
13581358
unix,
13591359
unlikely,
13601360
unmarked_api,
1361-
unnamed_fields,
13621361
unpin,
13631362
unreachable,
13641363
unreachable_code,

src/test/ui/feature-gates/feature-gate-unnamed_fields.rs

-27
This file was deleted.

src/test/ui/feature-gates/feature-gate-unnamed_fields.stderr

-111
This file was deleted.

0 commit comments

Comments
 (0)