Skip to content

Commit 05eb8e2

Browse files
committed
and now for tuples too
1 parent beec7f3 commit 05eb8e2

File tree

1 file changed

+14
-16
lines changed
  • compiler/rustc_borrowck/src

1 file changed

+14
-16
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
20122012
if (from..to).contains(offset) {
20132013
let uninit_child =
20142014
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?
20152016
maybe_uninits.contains(mpi)
20162017
});
20172018

@@ -2111,37 +2112,34 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
21112112

21122113
let path = &self.move_data.move_paths[mpi];
21132114

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();
21152118

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+
}
21232122

2124-
let variant = adt.non_enum_variant();
2123+
variant.fields.len()
2124+
}
2125+
ty::Tuple(tys) => tys.len(),
21252126

2126-
if variant.field_list_has_applicable_non_exhaustive() {
2127-
return true;
2128-
}
2127+
_ => return true,
2128+
};
21292129

21302130
// FIXME: destructors?
21312131

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.
21332133
// This means all of it's fields must have MovePaths
21342134
// because fields that are never written to will not have MovePaths.
21352135
// 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) {
21372137
// FIXME WrapUnsafeBinder?
21382138
if self.move_data.rev_lookup.project(mpi, ProjectionElem::Field(field, ())).is_none() {
21392139
return true;
21402140
}
21412141
}
21422142

2143-
debug!("sucess!!");
2144-
21452143
false
21462144
}
21472145

0 commit comments

Comments
 (0)