diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2017-11-30 16:09:27 -0300 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-12-13 06:03:28 -0500 |
| commit | 0c26d8fcd1b171beaf467d1e6ea0157b88bc5a2a (patch) | |
| tree | 1d7e03c189a99155c9a2d14f15f64b22c54cda0f | |
| parent | 14700e58b430ddddef037715778e452db8763ae9 (diff) | |
| download | rust-0c26d8fcd1b171beaf467d1e6ea0157b88bc5a2a.tar.gz rust-0c26d8fcd1b171beaf467d1e6ea0157b88bc5a2a.zip | |
Mir typeck Cast for Unsize value
| -rw-r--r-- | src/librustc_mir/transform/type_check.rs | 11 | ||||
| -rw-r--r-- | src/test/compile-fail/mir_check_cast_unsize.rs | 24 |
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() {} |
