Skip to content

MIR: split Operand::Consume into Copy and Move. #46142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 28, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rustc_mir: require that Copy(L) satisfies typeof L: Copy.
  • Loading branch information
eddyb committed Nov 28, 2017
commit 170b88dc79f6ac6e06a00ded1b97395b8a2c6f7a
29 changes: 23 additions & 6 deletions src/librustc_mir/transform/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc::ty::{self, Ty, TyCtxt, TypeVariants};
use rustc::middle::const_val::ConstVal;
use rustc::mir::*;
use rustc::mir::tcx::LvalueTy;
use rustc::mir::visit::Visitor;
use rustc::mir::visit::{LvalueContext, Visitor};
use std::fmt;
use syntax::ast;
use syntax_pos::{Span, DUMMY_SP};
Expand Down Expand Up @@ -107,10 +107,10 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
fn visit_lvalue(
&mut self,
lvalue: &Lvalue<'tcx>,
_context: visit::LvalueContext,
context: LvalueContext,
location: Location,
) {
self.sanitize_lvalue(lvalue, location);
self.sanitize_lvalue(lvalue, location, context);
}

fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
Expand Down Expand Up @@ -164,9 +164,13 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}
}

fn sanitize_lvalue(&mut self, lvalue: &Lvalue<'tcx>, location: Location) -> LvalueTy<'tcx> {
fn sanitize_lvalue(&mut self,
lvalue: &Lvalue<'tcx>,
location: Location,
context: LvalueContext)
-> LvalueTy<'tcx> {
debug!("sanitize_lvalue: {:?}", lvalue);
match *lvalue {
let lvalue_ty = match *lvalue {
Lvalue::Local(index) => LvalueTy::Ty {
ty: self.mir.local_decls[index].ty,
},
Expand All @@ -189,7 +193,12 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
LvalueTy::Ty { ty: sty }
}
Lvalue::Projection(ref proj) => {
let base_ty = self.sanitize_lvalue(&proj.base, location);
let base_context = if context.is_mutating_use() {
LvalueContext::Projection(Mutability::Mut)
} else {
LvalueContext::Projection(Mutability::Not)
};
let base_ty = self.sanitize_lvalue(&proj.base, location, base_context);
if let LvalueTy::Ty { ty } = base_ty {
if ty.references_error() {
assert!(self.errors_reported);
Expand All @@ -200,7 +209,15 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}
self.sanitize_projection(base_ty, &proj.elem, lvalue, location)
}
};
if let LvalueContext::Copy = context {
let ty = lvalue_ty.to_ty(self.tcx());
if self.cx.infcx.type_moves_by_default(self.cx.param_env, ty, DUMMY_SP) {
span_mirbug!(self, lvalue,
"attempted copy of non-Copy type ({:?})", ty);
}
}
lvalue_ty
}

fn sanitize_projection(
Expand Down