@@ -2012,6 +2012,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
2012
2012
if ( from..to) . contains ( offset) {
2013
2013
let uninit_child =
2014
2014
self . move_data . find_in_move_path_or_its_descendants ( child_mpi, |mpi| {
2015
+ // FIXME(structural_init) you can't partially init an array element, right?
2015
2016
maybe_uninits. contains ( mpi)
2016
2017
} ) ;
2017
2018
@@ -2111,37 +2112,34 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
2111
2112
2112
2113
let path = & self . move_data . move_paths [ mpi] ;
2113
2114
2114
- let ty = path. place . ty ( self . body ( ) , tcx) . ty ;
2115
+ let field_count = match path. place . ty ( self . body ( ) , tcx) . ty . kind ( ) {
2116
+ ty:: Adt ( adt, _) if adt. is_struct ( ) => {
2117
+ let variant = adt. non_enum_variant ( ) ;
2115
2118
2116
- let ty:: Adt ( adt, _) = ty. kind ( ) else {
2117
- return true ;
2118
- } ;
2119
-
2120
- if !adt. is_struct ( ) {
2121
- return true ;
2122
- }
2119
+ if variant. field_list_has_applicable_non_exhaustive ( ) {
2120
+ return true ;
2121
+ }
2123
2122
2124
- let variant = adt. non_enum_variant ( ) ;
2123
+ variant. fields . len ( )
2124
+ }
2125
+ ty:: Tuple ( tys) => tys. len ( ) ,
2125
2126
2126
- if variant. field_list_has_applicable_non_exhaustive ( ) {
2127
- return true ;
2128
- }
2127
+ _ => return true ,
2128
+ } ;
2129
2129
2130
2130
// FIXME: destructors?
2131
2131
2132
- // A structurally initialized ADT is "uninit" but all of it's fields are init.
2132
+ // A structurally initialized type is "uninit" but all of it's fields are init.
2133
2133
// This means all of it's fields must have MovePaths
2134
2134
// because fields that are never written to will not have MovePaths.
2135
2135
// Without this check, we may not detect that unwritten fields are uninit.
2136
- for field in variant . fields . indices ( ) {
2136
+ for field in ( 0 ..field_count ) . map ( FieldIdx :: from_usize ) {
2137
2137
// FIXME WrapUnsafeBinder?
2138
2138
if self . move_data . rev_lookup . project ( mpi, ProjectionElem :: Field ( field, ( ) ) ) . is_none ( ) {
2139
2139
return true ;
2140
2140
}
2141
2141
}
2142
2142
2143
- debug ! ( "sucess!!" ) ;
2144
-
2145
2143
false
2146
2144
}
2147
2145
0 commit comments