Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created August 30, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikomatsakis/150aae73abcdd09fbed63af253454479 to your computer and use it in GitHub Desktop.
Save nikomatsakis/150aae73abcdd09fbed63af253454479 to your computer and use it in GitHub Desktop.
diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
index f8f23731fb..7cdd76e9b7 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
@@ -258,6 +258,12 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
self.sanitize_type(constant, constant.ty);
}
+ fn visit_statement(&mut self, bb: BasicBlock, statement: &Statement<'tcx>, location: Location) {
+ let s = ::std::mem::replace(&mut self.last_span, statement.source_info.span);
+ self.super_statement(bb, statement, location);
+ self.last_span = s;
+ }
+
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
self.super_rvalue(rvalue, location);
let rval_ty = rvalue.ty(self.mir, self.tcx());
@@ -405,22 +411,6 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
PlaceTy::Ty { ty: sty }
}
};
- if let PlaceContext::Copy = context {
- let tcx = self.tcx();
- let trait_ref = ty::TraitRef {
- def_id: tcx.lang_items().copy_trait().unwrap(),
- substs: tcx.mk_substs_trait(place_ty.to_ty(tcx), &[]),
- };
-
- // In order to have a Copy operand, the type T of the value must be Copy. Note that we
- // prove that T: Copy, rather than using the type_moves_by_default test. This is
- // important because type_moves_by_default ignores the resulting region obligations and
- // assumes they pass. This can result in bounds from Copy impls being unsoundly ignored
- // (e.g., #29149). Note that we decide to use Copy before knowing whether the bounds
- // fully apply: in effect, the rule is that if a value of some type could implement
- // Copy, then it must.
- self.cx.prove_trait_ref(trait_ref, location.interesting());
- }
if !place.has_no_projection() {
for elem in place.elems.iter(){
@@ -442,6 +432,23 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}
};
+ if let PlaceContext::Copy = context {
+ let tcx = self.tcx();
+ let trait_ref = ty::TraitRef {
+ def_id: tcx.lang_items().copy_trait().unwrap(),
+ substs: tcx.mk_substs_trait(place_ty.to_ty(tcx), &[]),
+ };
+
+ // In order to have a Copy operand, the type T of the value must be Copy. Note that we
+ // prove that T: Copy, rather than using the type_moves_by_default test. This is
+ // important because type_moves_by_default ignores the resulting region obligations and
+ // assumes they pass. This can result in bounds from Copy impls being unsoundly ignored
+ // (e.g., #29149). Note that we decide to use Copy before knowing whether the bounds
+ // fully apply: in effect, the rule is that if a value of some type could implement
+ // Copy, then it must.
+ self.cx.prove_trait_ref(trait_ref, location.interesting());
+ }
+
place_ty
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment