mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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
@ -1902,10 +1902,6 @@ pub enum TyKind {
|
||||
Never,
|
||||
/// A tuple (`(A, B, C, D,...)`).
|
||||
Tup(Vec<P<Ty>>),
|
||||
/// An anonymous struct type i.e. `struct { foo: Type }`
|
||||
AnonymousStruct(Vec<FieldDef>, bool),
|
||||
/// An anonymous union type i.e. `union { bar: Type }`
|
||||
AnonymousUnion(Vec<FieldDef>, bool),
|
||||
/// A path (`module::module::...::Type`), optionally
|
||||
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
|
||||
///
|
||||
|
@ -484,9 +484,6 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
|
||||
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
|
||||
}
|
||||
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
|
||||
TyKind::AnonymousStruct(fields, ..) | TyKind::AnonymousUnion(fields, ..) => {
|
||||
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
|
||||
}
|
||||
}
|
||||
vis.visit_span(span);
|
||||
visit_lazy_tts(tokens, vis);
|
||||
|
@ -407,9 +407,6 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
|
||||
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
|
||||
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
|
||||
TyKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
|
||||
TyKind::AnonymousStruct(ref fields, ..) | TyKind::AnonymousUnion(ref fields, ..) => {
|
||||
walk_list!(visitor, visit_field_def, fields)
|
||||
}
|
||||
TyKind::Never | TyKind::CVarArgs => {}
|
||||
}
|
||||
}
|
||||
|
@ -748,10 +748,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn lower_field_def(
|
||||
&mut self,
|
||||
(index, f): (usize, &FieldDef),
|
||||
) -> hir::FieldDef<'hir> {
|
||||
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
|
||||
let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind {
|
||||
let t = self.lower_path_ty(
|
||||
&f.ty,
|
||||
|
@ -1289,15 +1289,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
let kind = match t.kind {
|
||||
TyKind::Infer => hir::TyKind::Infer,
|
||||
TyKind::Err => hir::TyKind::Err,
|
||||
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
|
||||
TyKind::AnonymousStruct(ref _fields, _recovered) => {
|
||||
self.sess.struct_span_err(t.span, "anonymous structs are unimplemented").emit();
|
||||
hir::TyKind::Err
|
||||
}
|
||||
TyKind::AnonymousUnion(ref _fields, _recovered) => {
|
||||
self.sess.struct_span_err(t.span, "anonymous unions are unimplemented").emit();
|
||||
hir::TyKind::Err
|
||||
}
|
||||
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
|
||||
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
|
||||
TyKind::Rptr(ref region, ref mt) => {
|
||||
|
@ -668,7 +668,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
|
||||
// involved, so we only emit errors where there are no other parsing errors.
|
||||
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
|
||||
}
|
||||
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");
|
||||
|
||||
// All uses of `gate_all!` below this point were added in #65742,
|
||||
// and subsequently disabled (with the non-early gating readded).
|
||||
|
@ -985,14 +985,6 @@ impl<'a> State<'a> {
|
||||
}
|
||||
self.pclose();
|
||||
}
|
||||
ast::TyKind::AnonymousStruct(ref fields, ..) => {
|
||||
self.s.word("struct");
|
||||
self.print_record_struct_body(fields, ty.span);
|
||||
}
|
||||
ast::TyKind::AnonymousUnion(ref fields, ..) => {
|
||||
self.s.word("union");
|
||||
self.print_record_struct_body(fields, ty.span);
|
||||
}
|
||||
ast::TyKind::Paren(ref typ) => {
|
||||
self.popen();
|
||||
self.print_type(typ);
|
||||
|
@ -639,9 +639,6 @@ declare_features! (
|
||||
/// Allows specifying the as-needed link modifier
|
||||
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),
|
||||
|
||||
/// Allows unnamed fields of struct and union type
|
||||
(incomplete, unnamed_fields, "1.53.0", Some(49804), None),
|
||||
|
||||
/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
|
||||
(active, more_qualified_paths, "1.54.0", Some(86935), None),
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -1358,7 +1358,6 @@ symbols! {
|
||||
unix,
|
||||
unlikely,
|
||||
unmarked_api,
|
||||
unnamed_fields,
|
||||
unpin,
|
||||
unreachable,
|
||||
unreachable_code,
|
||||
|
@ -1,27 +0,0 @@
|
||||
struct Foo {
|
||||
foo: u8,
|
||||
_: union { //~ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
//~^ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
//~| ERROR anonymous unions are unimplemented
|
||||
bar: u8,
|
||||
baz: u16
|
||||
}
|
||||
}
|
||||
|
||||
union Bar {
|
||||
foobar: u8,
|
||||
_: struct { //~ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
//~^ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
//~| ERROR anonymous structs are unimplemented
|
||||
//~| ERROR unions may not contain fields that need dropping [E0740]
|
||||
foobaz: u8,
|
||||
barbaz: u16
|
||||
}
|
||||
}
|
||||
|
||||
struct S;
|
||||
struct Baz {
|
||||
_: S //~ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
}
|
||||
|
||||
fn main(){}
|
@ -1,111 +0,0 @@
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:3:5
|
||||
|
|
||||
LL | _: union {
|
||||
| ^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:3:8
|
||||
|
|
||||
LL | _: union {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | bar: u8,
|
||||
LL | | baz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:5
|
||||
|
|
||||
LL | _: struct {
|
||||
| ^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:8
|
||||
|
|
||||
LL | _: struct {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | foobaz: u8,
|
||||
LL | | barbaz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:24:5
|
||||
|
|
||||
LL | _: S
|
||||
| ^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error: anonymous unions are unimplemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:3:8
|
||||
|
|
||||
LL | _: union {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | bar: u8,
|
||||
LL | | baz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:8
|
||||
|
|
||||
LL | _: struct {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | foobaz: u8,
|
||||
LL | | barbaz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error[E0740]: unions may not contain fields that need dropping
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:5
|
||||
|
|
||||
LL | / _: struct {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | foobaz: u8,
|
||||
LL | | barbaz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: `std::mem::ManuallyDrop` can be used to wrap the type
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:5
|
||||
|
|
||||
LL | / _: struct {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | foobaz: u8,
|
||||
LL | | barbaz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0658, E0740.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
Loading…
Reference in New Issue
Block a user