@@ -17,7 +17,10 @@ use smallvec::{SmallVec, smallvec};
1717use thin_vec:: ThinVec ;
1818use tracing:: instrument;
1919
20- use super :: errors:: { InvalidAbi , InvalidAbiReason , InvalidAbiSuggestion , MisplacedRelaxTraitBound } ;
20+ use super :: errors:: {
21+ InvalidAbi , InvalidAbiReason , InvalidAbiSuggestion , MisplacedRelaxTraitBound ,
22+ TupleStructWithDefault ,
23+ } ;
2124use super :: {
2225 AstOwner , FnDeclKind , ImplTraitContext , ImplTraitPosition , LoweringContext , ParamMode ,
2326 ResolverAstLoweringExt ,
@@ -690,13 +693,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
690693 VariantData :: Tuple ( fields, id) => {
691694 let ctor_id = self . lower_node_id ( * id) ;
692695 self . alias_attrs ( ctor_id, parent_id) ;
693- hir:: VariantData :: Tuple (
694- self . arena . alloc_from_iter (
695- fields. iter ( ) . enumerate ( ) . map ( |f| self . lower_field_def ( f) ) ,
696- ) ,
697- ctor_id,
698- self . local_def_id ( * id) ,
699- )
696+ let fields = self
697+ . arena
698+ . alloc_from_iter ( fields. iter ( ) . enumerate ( ) . map ( |f| self . lower_field_def ( f) ) ) ;
699+ for field in & fields[ ..] {
700+ if let Some ( default) = field. default {
701+ // Default values in tuple struct and tuple variants are not allowed by the
702+ // RFC due to concerns about the syntax, both in the item definition and the
703+ // expression. We could in the future allow `struct S(i32 = 0);` and force
704+ // users to construct the value with `let _ = S { .. };`.
705+ if self . tcx . features ( ) . default_field_values ( ) {
706+ self . dcx ( ) . emit_err ( TupleStructWithDefault { span : default. span } ) ;
707+ } else {
708+ let _ = self . dcx ( ) . span_delayed_bug (
709+ default. span ,
710+ "expected `default values on `struct` fields aren't supported` \
711+ feature-gate error but none was produced",
712+ ) ;
713+ }
714+ }
715+ }
716+ hir:: VariantData :: Tuple ( fields, ctor_id, self . local_def_id ( * id) )
700717 }
701718 VariantData :: Unit ( id) => {
702719 let ctor_id = self . lower_node_id ( * id) ;
0 commit comments