Skip to content

Commit

Permalink
Fix for issue 55748: force type of every binding to be equal to any a…
Browse files Browse the repository at this point in the history
…scription 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...?)
  • Loading branch information
pnkfelix committed Dec 19, 2018
1 parent eaf0621 commit e45dca5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,20 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
},
);
let place = Place::Local(local_id);
let var_ty = self.local_decls[local_id].ty;
let local_decl = &self.local_decls[local_id];
for (user_ty, ascription_span) in local_decl.user_ty.projections_and_spans() {
self.cfg.push(
block,
Statement {
source_info: self.source_info(*ascription_span),
kind: StatementKind::AscribeUserType(
Place::Local(local_id),
ty::Variance::Invariant,
Box::new(user_ty.clone()),
),
});
}
let var_ty = local_decl.ty;
let hir_id = self.hir.tcx().hir().node_to_hir_id(var);
let region_scope = self.hir.region_scope_tree.var_scope(hir_id.local_id);
self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage);
Expand Down

0 comments on commit e45dca5

Please sign in to comment.