@@ -193,19 +193,13 @@ impl<'a> AstValidator<'a> {
193193 }
194194 }
195195 }
196- TyKind :: AnonymousStruct ( ref fields, ..) | TyKind :: AnonymousUnion ( ref fields, ..) => {
197- self . with_banned_assoc_ty_bound ( |this| {
198- walk_list ! ( this, visit_struct_field_def, fields)
199- } ) ;
200- }
201196 _ => visit:: walk_ty ( self , t) ,
202197 }
203198 }
204199
205200 fn visit_struct_field_def ( & mut self , field : & ' a FieldDef ) {
206201 if let Some ( ident) = field. ident {
207202 if ident. name == kw:: Underscore {
208- self . check_anonymous_field ( field) ;
209203 self . visit_vis ( & field. vis ) ;
210204 self . visit_ident ( ident) ;
211205 self . visit_ty_common ( & field. ty ) ;
@@ -251,66 +245,6 @@ impl<'a> AstValidator<'a> {
251245 err. emit ( ) ;
252246 }
253247
254- fn check_anonymous_field ( & self , field : & FieldDef ) {
255- let FieldDef { ty, .. } = field;
256- match & ty. kind {
257- TyKind :: AnonymousStruct ( ..) | TyKind :: AnonymousUnion ( ..) => {
258- // We already checked for `kw::Underscore` before calling this function,
259- // so skip the check
260- }
261- TyKind :: Path ( ..) => {
262- // If the anonymous field contains a Path as type, we can't determine
263- // if the path is a valid struct or union, so skip the check
264- }
265- _ => {
266- let msg = "unnamed fields can only have struct or union types" ;
267- let label = "not a struct or union" ;
268- self . err_handler ( )
269- . struct_span_err ( field. span , msg)
270- . span_label ( ty. span , label)
271- . emit ( ) ;
272- }
273- }
274- }
275-
276- fn deny_anonymous_struct ( & self , ty : & Ty ) {
277- match & ty. kind {
278- TyKind :: AnonymousStruct ( ..) => {
279- self . err_handler ( )
280- . struct_span_err (
281- ty. span ,
282- "anonymous structs are not allowed outside of unnamed struct or union fields" ,
283- )
284- . span_label ( ty. span , "anonymous struct declared here" )
285- . emit ( ) ;
286- }
287- TyKind :: AnonymousUnion ( ..) => {
288- self . err_handler ( )
289- . struct_span_err (
290- ty. span ,
291- "anonymous unions are not allowed outside of unnamed struct or union fields" ,
292- )
293- . span_label ( ty. span , "anonymous union declared here" )
294- . emit ( ) ;
295- }
296- _ => { }
297- }
298- }
299-
300- fn deny_anonymous_field ( & self , field : & FieldDef ) {
301- if let Some ( ident) = field. ident {
302- if ident. name == kw:: Underscore {
303- self . err_handler ( )
304- . struct_span_err (
305- field. span ,
306- "anonymous fields are not allowed outside of structs or unions" ,
307- )
308- . span_label ( ident. span , "anonymous field declared here" )
309- . emit ( )
310- }
311- }
312- }
313-
314248 fn check_decl_no_pat ( decl : & FnDecl , mut report_err : impl FnMut ( Span , Option < Ident > , bool ) ) {
315249 for Param { pat, .. } in & decl. inputs {
316250 match pat. kind {
@@ -1081,7 +1015,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10811015
10821016 fn visit_ty ( & mut self , ty : & ' a Ty ) {
10831017 self . visit_ty_common ( ty) ;
1084- self . deny_anonymous_struct ( ty) ;
10851018 self . walk_ty ( ty)
10861019 }
10871020
@@ -1096,7 +1029,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10961029 }
10971030
10981031 fn visit_field_def ( & mut self , s : & ' a FieldDef ) {
1099- self . deny_anonymous_field ( s) ;
11001032 visit:: walk_field_def ( self , s)
11011033 }
11021034
0 commit comments