]> git.lizzy.rs Git - rust.git/commitdiff
trans: monomorphize the cast destination type before using it.
authorEduard Burtescu <edy.burt@gmail.com>
Sat, 7 May 2016 17:00:42 +0000 (20:00 +0300)
committerEduard Burtescu <edy.burt@gmail.com>
Mon, 9 May 2016 06:20:02 +0000 (09:20 +0300)
src/librustc_trans/mir/rvalue.rs
src/test/run-pass/mir_coercions.rs

index 1236100a4d51c08a1bfe4dab4243984e6352ee03..45b6bcd920fdf7322e6f244575129d8ef1db2758 100644 (file)
@@ -55,6 +55,8 @@ pub fn trans_rvalue(&mut self,
            }
 
             mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => {
+                let cast_ty = bcx.monomorphize(&cast_ty);
+
                 if common::type_is_fat_ptr(bcx.tcx(), cast_ty) {
                     // into-coerce of a thin pointer to a fat pointer - just
                     // use the operand path.
index c1897f79f22c6e9652541b24736be7669d7ed677..09dd52e30bef9ff7e1bd8c2db70ed5d410c64a6f 100644 (file)
@@ -55,6 +55,13 @@ fn coerce_fat_ptr_wrapper(p: PtrWrapper<Fn(u32) -> u32+Send>)
     p
 }
 
+#[rustc_mir]
+fn coerce_ptr_wrapper_poly<'a, T, Trait: ?Sized>(p: PtrWrapper<'a, T>)
+                                                 -> PtrWrapper<'a, Trait>
+    where PtrWrapper<'a, T>: CoerceUnsized<PtrWrapper<'a, Trait>>
+{
+    p
+}
 
 fn main() {
     let a = [0,1,2];
@@ -73,4 +80,8 @@ fn main() {
 
     let z = coerce_fat_ptr_wrapper(PtrWrapper(2,3,(),&square_local));
     assert_eq!((z.3)(6), 36);
+
+    let z: PtrWrapper<Fn(u32) -> u32> =
+        coerce_ptr_wrapper_poly(PtrWrapper(2,3,(),&square_local));
+    assert_eq!((z.3)(6), 36);
 }