about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_mir/transform/type_check.rs11
-rw-r--r--src/test/compile-fail/mir_check_cast_unsize.rs24
2 files changed, 34 insertions, 1 deletions
diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs
index 00e60bd1910..0de258f6ed7 100644
--- a/src/librustc_mir/transform/type_check.rs
+++ b/src/librustc_mir/transform/type_check.rs
@@ -1218,7 +1218,16 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
                         }
                     }
 
-                    CastKind::Misc | CastKind::Unsize => {}
+                    CastKind::Unsize => {
+                        let trait_ref = ty::TraitRef {
+                            def_id: tcx.lang_items().coerce_unsized_trait().unwrap(),
+                            substs: tcx.mk_substs_trait(op.ty(mir, tcx), &[ty]),
+                        };
+
+                        self.prove_trait_ref(trait_ref, location);
+                    }
+
+                    CastKind::Misc => {}
                 }
             }
 
diff --git a/src/test/compile-fail/mir_check_cast_unsize.rs b/src/test/compile-fail/mir_check_cast_unsize.rs
new file mode 100644
index 00000000000..bc867047ab5
--- /dev/null
+++ b/src/test/compile-fail/mir_check_cast_unsize.rs
@@ -0,0 +1,24 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -Z borrowck=mir -Z nll
+
+#![allow(dead_code)]
+#![feature(dyn_trait)]
+
+use std::fmt::Debug;
+
+fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
+    //~^ ERROR free region `'_#1r` does not outlive free region `'static`
+    x
+    //~^ WARNING not reporting region error due to -Znll
+}
+
+fn main() {}