@@ -415,24 +415,18 @@ impl ModuleDef {
415415 def. diagnostics ( db, & mut acc) ;
416416 }
417417
418- let vd: Option < ( VariantDef , Arc < VariantData > ) > = match self {
419- ModuleDef :: Adt ( Adt :: Struct ( it) ) => {
420- Some ( ( it. into ( ) , db. struct_data ( it. id ) . variant_data . clone ( ) ) )
421- }
422- ModuleDef :: Adt ( Adt :: Union ( it) ) => {
423- Some ( ( it. into ( ) , db. union_data ( it. id ) . variant_data . clone ( ) ) )
424- }
425- ModuleDef :: Variant ( it) => {
426- Some ( ( it. into ( ) , db. enum_variant_data ( it. id ) . variant_data . clone ( ) ) )
427- }
418+ let fields = match self {
419+ ModuleDef :: Adt ( Adt :: Struct ( it) ) => Some ( it. fields ( db) ) ,
420+ ModuleDef :: Adt ( Adt :: Union ( it) ) => Some ( it. fields ( db) ) ,
421+ ModuleDef :: Variant ( it) => Some ( it. fields ( db) ) ,
428422 _ => None ,
429423 } ;
430- if let Some ( ( parent , vd ) ) = vd {
431- for ( id , fd ) in vd . fields ( ) . iter ( ) {
432- if !fd . has_default {
424+ if let Some ( fields ) = fields {
425+ for field in fields {
426+ if !field . has_default {
433427 continue ;
434428 }
435- let def: DefWithBody = DefWithBody :: Field ( Field { parent , id } ) ;
429+ let def: DefWithBody = field . into ( ) ;
436430 def. diagnostics ( db, & mut acc, style_lints) ;
437431 }
438432 }
@@ -1258,6 +1252,7 @@ impl From<&Field> for DefWithBodyId {
12581252pub struct Field {
12591253 pub ( crate ) parent : VariantDef ,
12601254 pub ( crate ) id : LocalFieldId ,
1255+ pub ( crate ) has_default : bool ,
12611256}
12621257
12631258#[ derive( Debug , PartialEq , Eq , Copy , Clone , Hash ) ]
@@ -1423,7 +1418,7 @@ impl Struct {
14231418 . variant_data
14241419 . fields ( )
14251420 . iter ( )
1426- . map ( |( id, _ ) | Field { parent : self . into ( ) , id } )
1421+ . map ( |( id, d ) | Field { parent : self . into ( ) , id, has_default : d . has_default } )
14271422 . collect ( )
14281423 }
14291424
@@ -1485,7 +1480,7 @@ impl Union {
14851480 . variant_data
14861481 . fields ( )
14871482 . iter ( )
1488- . map ( |( id, _ ) | Field { parent : self . into ( ) , id } )
1483+ . map ( |( id, d ) | Field { parent : self . into ( ) , id, has_default : d . has_default } )
14891484 . collect ( )
14901485 }
14911486
@@ -1615,7 +1610,7 @@ impl Variant {
16151610 self . variant_data ( db)
16161611 . fields ( )
16171612 . iter ( )
1618- . map ( |( id, _ ) | Field { parent : self . into ( ) , id } )
1613+ . map ( |( id, d ) | Field { parent : self . into ( ) , id, has_default : d . has_default } )
16191614 . collect ( )
16201615 }
16211616
@@ -5203,10 +5198,13 @@ impl Type {
52035198 _ => return Vec :: new ( ) ,
52045199 } ;
52055200
5201+ let var_data = db. variant_data ( variant_id) ;
5202+ let fields = var_data. fields ( ) ;
52065203 db. field_types ( variant_id)
52075204 . iter ( )
52085205 . map ( |( local_id, ty) | {
5209- let def = Field { parent : variant_id. into ( ) , id : local_id } ;
5206+ let has_default = fields[ local_id] . has_default ;
5207+ let def = Field { parent : variant_id. into ( ) , id : local_id, has_default } ;
52105208 let ty = ty. clone ( ) . substitute ( Interner , substs) ;
52115209 ( def, self . derived ( ty) )
52125210 } )
0 commit comments