Skip to content

Commit 0c26d8f

Browse files
spastorinonikomatsakis
authored andcommitted
Mir typeck Cast for Unsize value
1 parent 14700e5 commit 0c26d8f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/librustc_mir/transform/type_check.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,16 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12181218
}
12191219
}
12201220

1221-
CastKind::Misc | CastKind::Unsize => {}
1221+
CastKind::Unsize => {
1222+
let trait_ref = ty::TraitRef {
1223+
def_id: tcx.lang_items().coerce_unsized_trait().unwrap(),
1224+
substs: tcx.mk_substs_trait(op.ty(mir, tcx), &[ty]),
1225+
};
1226+
1227+
self.prove_trait_ref(trait_ref, location);
1228+
}
1229+
1230+
CastKind::Misc => {}
12221231
}
12231232
}
12241233

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z borrowck=mir -Z nll
12+
13+
#![allow(dead_code)]
14+
#![feature(dyn_trait)]
15+
16+
use std::fmt::Debug;
17+
18+
fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
19+
//~^ ERROR free region `'_#1r` does not outlive free region `'static`
20+
x
21+
//~^ WARNING not reporting region error due to -Znll
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)