Skip to content

Commit 6f8fb91

Browse files
authoredJul 16, 2022
Rollup merge of rust-lang#98582 - oli-obk:unconstrained_opaque_type, r=estebank
Allow destructuring opaque types in their defining scopes fixes rust-lang#96572 Before this PR, the following code snippet failed with an incomprehensible error, and similar code just ICEd in mir borrowck. ```rust type T = impl Copy; let foo: T = (1u32, 2u32); let (a, b) = foo; ``` The problem was that the last line created MIR projections of the form `foo.0` and `foo.1`, but `foo`'s type is `T`, which doesn't have fields (only its hidden type does). But the pattern supplies enough type information (a tuple of two different inference types) to bind a hidden type.
2 parents 7210e46 + 57e9f7a commit 6f8fb91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+396
-205
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20932093
}
20942094
StorageDeadOrDrop::Destructor(_) => kind,
20952095
},
2096-
ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
2096+
ProjectionElem::OpaqueCast { .. }
2097+
| ProjectionElem::Field(..)
2098+
| ProjectionElem::Downcast(..) => {
20972099
match place_ty.ty.kind() {
20982100
ty::Adt(def, _) if def.has_dtor(tcx) => {
20992101
// Report the outermost adt with a destructor

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
226226
}
227227
ProjectionElem::Downcast(..) if including_downcast.0 => return None,
228228
ProjectionElem::Downcast(..) => (),
229+
ProjectionElem::OpaqueCast(..) => (),
229230
ProjectionElem::Field(field, _ty) => {
230231
// FIXME(project-rfc_2229#36): print capture precisely here.
231232
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
@@ -286,6 +287,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
286287
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
287288
}
288289
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
290+
ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(*ty),
289291
ProjectionElem::Field(_, field_type) => PlaceTy::from_ty(*field_type),
290292
},
291293
};

0 commit comments

Comments
 (0)