@@ -1992,6 +1992,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19921992 if ( from..to) . contains ( offset) {
19931993 let uninit_child =
19941994 self . move_data . find_in_move_path_or_its_descendants ( child_mpi, |mpi| {
1995+ // FIXME(structural_init) you can't partially init an array element, right?
19951996 maybe_uninits. contains ( mpi)
19961997 } ) ;
19971998
@@ -2091,37 +2092,34 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
20912092
20922093 let path = & self . move_data . move_paths [ mpi] ;
20932094
2094- let ty = path. place . ty ( self . body ( ) , tcx) . ty ;
2095+ let field_count = match path. place . ty ( self . body ( ) , tcx) . ty . kind ( ) {
2096+ ty:: Adt ( adt, _) if adt. is_struct ( ) => {
2097+ let variant = adt. non_enum_variant ( ) ;
20952098
2096- let ty:: Adt ( adt, _) = ty. kind ( ) else {
2097- return true ;
2098- } ;
2099-
2100- if !adt. is_struct ( ) {
2101- return true ;
2102- }
2099+ if variant. field_list_has_applicable_non_exhaustive ( ) {
2100+ return true ;
2101+ }
21032102
2104- let variant = adt. non_enum_variant ( ) ;
2103+ variant. fields . len ( )
2104+ }
2105+ ty:: Tuple ( tys) => tys. len ( ) ,
21052106
2106- if variant. field_list_has_applicable_non_exhaustive ( ) {
2107- return true ;
2108- }
2107+ _ => return true ,
2108+ } ;
21092109
21102110 // FIXME: destructors?
21112111
2112- // A structurally initialized ADT is "uninit" but all of it's fields are init.
2112+ // A structurally initialized type is "uninit" but all of it's fields are init.
21132113 // This means all of it's fields must have MovePaths
21142114 // because fields that are never written to will not have MovePaths.
21152115 // Without this check, we may not detect that unwritten fields are uninit.
2116- for field in variant . fields . indices ( ) {
2116+ for field in ( 0 ..field_count ) . map ( FieldIdx :: from_usize ) {
21172117 // FIXME WrapUnsafeBinder?
21182118 if self . move_data . rev_lookup . project ( mpi, ProjectionElem :: Field ( field, ( ) ) ) . is_none ( ) {
21192119 return true ;
21202120 }
21212121 }
21222122
2123- debug ! ( "sucess!!" ) ;
2124-
21252123 false
21262124 }
21272125
0 commit comments