Skip to content

Commit 35c77c3

Browse files
authored
Merge branch 'master' into closures
2 parents f095562 + 3f3fada commit 35c77c3

File tree

6 files changed

+63
-41
lines changed

6 files changed

+63
-41
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ before_script:
1010
- cargo install xargo
1111
- export RUST_SYSROOT=$HOME/rust
1212
script:
13+
- set -e
1314
- |
1415
# get ourselves a MIR-ful libstd
1516
xargo/build.sh

src/librustc_mir/interpret/eval_context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,12 @@ fn resolve_associated_item<'a, 'tcx>(
22752275
substs: rcvr_substs,
22762276
}
22772277
}
2278+
::rustc::traits::VtableBuiltin(..) if Some(trait_id) == tcx.lang_items.clone_trait() => {
2279+
ty::Instance {
2280+
def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()),
2281+
substs: rcvr_substs
2282+
}
2283+
}
22782284
_ => bug!("static call to invalid vtable: {:?}", vtbl),
22792285
}
22802286
}

src/librustc_mir/interpret/terminator/mod.rs

+5-41
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
256256
self.dump_local(ret);
257257
Ok(())
258258
}
259+
// FIXME: figure out why we can't just go through the shim
259260
ty::InstanceDef::ClosureOnceShim { .. } => {
260261
let mut args = Vec::new();
261262
for arg in arg_operands {
@@ -297,6 +298,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
297298
}
298299
Ok(())
299300
}
301+
ty::InstanceDef::FnPtrShim(..) |
302+
ty::InstanceDef::DropGlue(..) |
303+
ty::InstanceDef::CloneShim(..) |
300304
ty::InstanceDef::Item(_) => {
301305
let mut args = Vec::new();
302306
for arg in arg_operands {
@@ -394,47 +398,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
394398
}
395399
Ok(())
396400
}
397-
ty::InstanceDef::DropGlue(..) => {
398-
assert_eq!(arg_operands.len(), 1);
399-
assert_eq!(sig.abi, Abi::Rust);
400-
let val = self.eval_operand(&arg_operands[0])?;
401-
let ty = self.operand_ty(&arg_operands[0]);
402-
let (_, target) = destination.expect("diverging drop glue");
403-
self.goto_block(target);
404-
// FIXME: deduplicate these matches
405-
let pointee_type = match ty.sty {
406-
ty::TyRawPtr(ref tam) |
407-
ty::TyRef(_, ref tam) => tam.ty,
408-
ty::TyAdt(def, _) if def.is_box() => ty.boxed_ty(),
409-
_ => bug!("can only deref pointer types"),
410-
};
411-
self.drop(val, instance, pointee_type, span)
412-
}
413-
ty::InstanceDef::FnPtrShim(..) => {
414-
trace!("ABI: {}", sig.abi);
415-
let mut args = Vec::new();
416-
for arg in arg_operands {
417-
let arg_val = self.eval_operand(arg)?;
418-
let arg_ty = self.operand_ty(arg);
419-
args.push((arg_val, arg_ty));
420-
}
421-
if M::eval_fn_call(self, instance, destination, arg_operands, span, sig)? {
422-
return Ok(());
423-
}
424-
let arg_locals = self.frame().mir.args_iter();
425-
match sig.abi {
426-
Abi::Rust => {
427-
args.remove(0);
428-
}
429-
Abi::RustCall => {}
430-
_ => unimplemented!(),
431-
};
432-
for (arg_local, (arg_val, arg_ty)) in arg_locals.zip(args) {
433-
let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
434-
self.write_value(arg_val, dest, arg_ty)?;
435-
}
436-
Ok(())
437-
}
401+
// cannot use the shim here, because that will only result in infinite recursion
438402
ty::InstanceDef::Virtual(_, idx) => {
439403
let ptr_size = self.memory.pointer_size();
440404
let (_, vtable) = self.eval_operand(&arg_operands[0])?.into_ptr_vtable_pair(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![allow(unused_variables)]
2+
3+
// For some reason, the error location is different when using fullmir
4+
// error-pattern: in conflict with lock WriteLock
5+
6+
mod safe {
7+
use std::slice::from_raw_parts_mut;
8+
9+
pub fn as_mut_slice<T>(self_: &Vec<T>) -> &mut [T] {
10+
unsafe {
11+
from_raw_parts_mut(self_.as_ptr() as *mut T, self_.len())
12+
}
13+
}
14+
}
15+
16+
fn main() {
17+
let v = vec![0,1,2];
18+
let v1_ = safe::as_mut_slice(&v);
19+
let v2_ = safe::as_mut_slice(&v);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
trait Id {
2+
type Out;
3+
4+
fn id(self) -> Self::Out;
5+
}
6+
7+
impl<'a> Id for &'a mut i32 {
8+
type Out = &'a mut i32;
9+
10+
fn id(self) -> Self { self }
11+
}
12+
13+
impl<'a> Id for &'a mut u32 {
14+
type Out = &'a mut u32;
15+
16+
fn id(self) -> Self { self }
17+
}
18+
19+
fn foo<T>(mut x: T) where for<'a> &'a mut T: Id
20+
{
21+
let x = &mut x;
22+
let _y = x.id();
23+
// Inspecting the trace should show that _y has a type involving a local lifetime, when it gets validated.
24+
// Unfortunately, there doesn't seem to be a way to actually have a test fail if it does not have the right
25+
// type. Currently, this is NOT working correctly; see <https://github.com/solson/miri/issues/298>.
26+
}
27+
28+
fn main() {
29+
foo(3)
30+
}

xargo/build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/sh
22
cd "$(dirname "$0")"
3+
sed 's/gcc = "0\.3\.50"/gcc = "=0\.3\.50"/' -i ~/.rustup/toolchains/*/lib/rustlib/src/rust/src/libstd/Cargo.toml
34
RUSTFLAGS='-Zalways-encode-mir -Zmir-emit-validate=1' xargo build

0 commit comments

Comments
 (0)