@@ -271,7 +271,6 @@ declare_features! (
271271 // Allows `impl Trait` in function return types.
272272 ( active, conservative_impl_trait, "1.12.0" , Some ( 34511 ) ) ,
273273
274- // Allows tuple structs and variants in more contexts,
275274 // Permits numeric fields in struct expressions and patterns.
276275 ( active, relaxed_adts, "1.12.0" , Some ( 35626 ) ) ,
277276
@@ -996,6 +995,10 @@ fn contains_novel_literal(item: &ast::MetaItem) -> bool {
996995 }
997996}
998997
998+ fn starts_with_digit ( s : & str ) -> bool {
999+ s. as_bytes ( ) . first ( ) . cloned ( ) . map_or ( false , |b| b >= b'0' && b <= b'9' )
1000+ }
1001+
9991002impl < ' a > Visitor for PostExpansionVisitor < ' a > {
10001003 fn visit_attribute ( & mut self , attr : & ast:: Attribute ) {
10011004 if !self . context . cm . span_allows_unstable ( attr. span ) {
@@ -1175,6 +1178,11 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
11751178 gate_feature_post ! ( & self , field_init_shorthand, field. span,
11761179 "struct field shorthands are unstable" ) ;
11771180 }
1181+ if starts_with_digit ( & field. ident . node . name . as_str ( ) ) {
1182+ gate_feature_post ! ( & self , relaxed_adts,
1183+ field. span,
1184+ "numeric fields in struct expressions are unstable" ) ;
1185+ }
11781186 }
11791187 }
11801188 _ => { }
@@ -1201,10 +1209,14 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
12011209 pattern. span,
12021210 "box pattern syntax is experimental" ) ;
12031211 }
1204- PatKind :: TupleStruct ( _, ref fields, ddpos)
1205- if ddpos. is_none ( ) && fields. is_empty ( ) => {
1206- gate_feature_post ! ( & self , relaxed_adts, pattern. span,
1207- "empty tuple structs patterns are unstable" ) ;
1212+ PatKind :: Struct ( _, ref fields, _) => {
1213+ for field in fields {
1214+ if starts_with_digit ( & field. node . ident . name . as_str ( ) ) {
1215+ gate_feature_post ! ( & self , relaxed_adts,
1216+ field. span,
1217+ "numeric fields in struct patterns are unstable" ) ;
1218+ }
1219+ }
12081220 }
12091221 _ => { }
12101222 }
@@ -1287,19 +1299,6 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
12871299 visit:: walk_impl_item ( self , ii) ;
12881300 }
12891301
1290- fn visit_variant_data ( & mut self , vdata : & ast:: VariantData , _: ast:: Ident ,
1291- _: & ast:: Generics , _: NodeId , span : Span ) {
1292- if vdata. fields ( ) . is_empty ( ) {
1293- if vdata. is_tuple ( ) {
1294- gate_feature_post ! ( & self , relaxed_adts, span,
1295- "empty tuple structs and enum variants are unstable, \
1296- use unit structs and enum variants instead") ;
1297- }
1298- }
1299-
1300- visit:: walk_struct_def ( self , vdata)
1301- }
1302-
13031302 fn visit_vis ( & mut self , vis : & ast:: Visibility ) {
13041303 let span = match * vis {
13051304 ast:: Visibility :: Crate ( span) => span,
0 commit comments