1
Fork 0

fix some ICEs

This commit is contained in:
Oliver Schneider 2017-01-28 15:28:24 +01:00
parent 8f7e492305
commit b6e79dbbf5
2 changed files with 17 additions and 1 deletions

View file

@ -223,7 +223,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
pub fn monomorphize(&self, ty: Ty<'tcx>, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {
let substituted = ty.subst(self.tcx, substs);
// miri doesn't care about lifetimes, and will choke on some crazy ones
// let's simply get rid of them
let without_lifetimes = self.tcx.erase_regions(&ty);
let substituted = without_lifetimes.subst(self.tcx, substs);
self.tcx.normalize_associated_type(&substituted)
}

View file

@ -4,8 +4,21 @@ struct A<'a> {
y: &'a i32,
}
#[derive(Copy, Clone, PartialEq, Debug)]
struct B<'a>(i32, &'a i32);
fn main() {
let x = 5;
let a = A { x: 99, y: &x };
assert_eq!(Some(a).map(Some), Some(Some(a)));
let f = B;
assert_eq!(Some(B(42, &x)), Some(f(42, &x)));
// the following doesn't compile :(
//let f: for<'a> fn(i32, &'a i32) -> B<'a> = B;
//assert_eq!(Some(B(42, &x)), Some(f(42, &x)));
assert_eq!(B(42, &x), foo(&x, B));
}
fn foo<'a, F: Fn(i32, &'a i32) -> B<'a>>(i: &'a i32, f: F) -> B<'a> {
f(42, i)
}