From 0c26d8fcd1b171beaf467d1e6ea0157b88bc5a2a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 30 Nov 2017 16:09:27 -0300 Subject: [PATCH] Mir typeck Cast for Unsize value --- src/librustc_mir/transform/type_check.rs | 11 ++++++++- .../compile-fail/mir_check_cast_unsize.rs | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/mir_check_cast_unsize.rs diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index 00e60bd191048..0de258f6ed735 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 0000000000000..bc867047ab5b3 --- /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 or the MIT license +// , 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() {}