Skip to content

Commit ea6c448

Browse files
committed
Disable the recovery of anonymous structs or unions
1 parent bdaa0c9 commit ea6c448

File tree

7 files changed

+73
-685
lines changed

7 files changed

+73
-685
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

-6
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ impl<'a> AstValidator<'a> {
220220
}
221221
}
222222
TyKind::AnonStruct(ref fields, ..) | TyKind::AnonUnion(ref fields, ..) => {
223-
// self.with_banned_assoc_ty_bound(|this| {
224223
walk_list!(self, visit_field_def, fields)
225-
// });
226224
}
227225
_ => visit::walk_ty(self, t),
228226
}
@@ -1059,9 +1057,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10591057
self.visit_vis(&item.vis);
10601058
self.visit_ident(item.ident);
10611059
self.visit_generics(generics);
1062-
// self.with_banned_assoc_ty_bound(|this| {
10631060
walk_list!(self, visit_struct_field_def, fields);
1064-
// });
10651061
walk_list!(self, visit_attribute, &item.attrs);
10661062
return;
10671063
}
@@ -1076,9 +1072,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10761072
self.visit_vis(&item.vis);
10771073
self.visit_ident(item.ident);
10781074
self.visit_generics(generics);
1079-
// self.with_banned_assoc_ty_bound(|this| {
10801075
walk_list!(self, visit_struct_field_def, fields);
1081-
// });
10821076
walk_list!(self, visit_attribute, &item.attrs);
10831077
return;
10841078
}

compiler/rustc_parse/src/parser/item.rs

+3-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::diagnostics::{dummy_arg, ConsumeClosingDelim};
2-
use super::ty::{AllowAnonStructOrUnion, AllowPlus, RecoverQPath, RecoverReturnSign};
2+
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
33
use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken};
44
use crate::errors::{self, MacroExpandsToAdtField};
55
use crate::fluent_generated as fluent;
@@ -590,7 +590,7 @@ impl<'a> Parser<'a> {
590590
self.bump(); // `..`, do not add it to expected tokens
591591
Some(self.mk_ty(self.prev_token.span, TyKind::Err))
592592
} else if has_for || self.token.can_begin_type() {
593-
Some(self.parse_second_ty_for_item_impl()?)
593+
Some(self.parse_ty()?)
594594
} else {
595595
None
596596
};
@@ -1595,26 +1595,11 @@ impl<'a> Parser<'a> {
15951595
Ok((class_name, ItemKind::Union(vdata, generics)))
15961596
}
15971597

1598-
fn parse_record_struct_body(
1598+
pub(crate) fn parse_record_struct_body(
15991599
&mut self,
16001600
adt_ty: &str,
16011601
ident_span: Span,
16021602
parsed_where: bool,
1603-
) -> PResult<'a, (ThinVec<FieldDef>, /* recovered */ bool)> {
1604-
self.parse_record_struct_body_common(
1605-
adt_ty,
1606-
ident_span,
1607-
parsed_where,
1608-
AllowAnonStructOrUnion::Yes,
1609-
)
1610-
}
1611-
1612-
pub(crate) fn parse_record_struct_body_common(
1613-
&mut self,
1614-
adt_ty: &str,
1615-
ident_span: Span,
1616-
parsed_where: bool,
1617-
allow_anon_struct_or_union: AllowAnonStructOrUnion<'a>,
16181603
) -> PResult<'a, (ThinVec<FieldDef>, /* recovered */ bool)> {
16191604
let mut fields = ThinVec::new();
16201605
let mut recovered = false;
@@ -1628,18 +1613,6 @@ impl<'a> Parser<'a> {
16281613
match field {
16291614
Ok(field) => fields.push(field),
16301615
Err(mut err) => {
1631-
// When recovering the anonymous structs or unions, we should't emit the error
1632-
// immediately, because it may also be a type path `union` followed by a block,
1633-
// such as `impl union { fn foo() {} }`. Here we are actaully not parsing a
1634-
// record struct body but an `impl` body.
1635-
//
1636-
// Instead, the error should be thrown and handled by the caller
1637-
// `parse_anon_struct_or_union`.
1638-
if let AllowAnonStructOrUnion::RecoverNonEmptyOrElse(_) =
1639-
allow_anon_struct_or_union
1640-
{
1641-
return Err(err);
1642-
}
16431616
err.span_label(ident_span, format!("while parsing this {adt_ty}"));
16441617
err.emit();
16451618
break;

0 commit comments

Comments
 (0)