Skip to content

Commit

Permalink
Mir typeck Cast for Unsize value
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino authored and nikomatsakis committed Dec 13, 2017
1 parent 14700e5 commit 0c26d8f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/librustc_mir/transform/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/mir_check_cast_unsize.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 0c26d8f

Please sign in to comment.