Skip to content

Commit e45dca5

Browse files
committed
Fix for issue 55748: force type of every binding to be equal to any ascription given for its pattern.
I chose to attach this to the point immediately after we emit `StorageLive` but its possible that is not the best spot to encode this `AscribeUserType`. * Still, the approach makes sense in my head: The storage is live here so the regions used by its type should be valid at this point, I think? * The only other alternative I could imagine is to delay the `AscribeUserType` until the point immediately before we assign a value to the binding...?)
1 parent eaf0621 commit e45dca5

File tree

1 file changed

+14
-1
lines changed
  • src/librustc_mir/build/matches

1 file changed

+14
-1
lines changed

src/librustc_mir/build/matches/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,20 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
472472
},
473473
);
474474
let place = Place::Local(local_id);
475-
let var_ty = self.local_decls[local_id].ty;
475+
let local_decl = &self.local_decls[local_id];
476+
for (user_ty, ascription_span) in local_decl.user_ty.projections_and_spans() {
477+
self.cfg.push(
478+
block,
479+
Statement {
480+
source_info: self.source_info(*ascription_span),
481+
kind: StatementKind::AscribeUserType(
482+
Place::Local(local_id),
483+
ty::Variance::Invariant,
484+
Box::new(user_ty.clone()),
485+
),
486+
});
487+
}
488+
let var_ty = local_decl.ty;
476489
let hir_id = self.hir.tcx().hir().node_to_hir_id(var);
477490
let region_scope = self.hir.region_scope_tree.var_scope(hir_id.local_id);
478491
self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage);

0 commit comments

Comments
 (0)