Skip to content

Commit 900d4d5

Browse files
spastorinonikomatsakis
authored andcommitted
Mir typeck Cast for UnsafeFnPtr value
1 parent 7d56131 commit 900d4d5

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/librustc_mir/transform/type_check.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,11 +1196,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11961196
}
11971197
}
11981198

1199+
CastKind::UnsafeFnPointer => {
1200+
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(op.ty(mir, tcx).fn_sig(tcx));
1201+
1202+
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.at_self()) {
1203+
span_mirbug!(self, "", "casting {:?}", terr);
1204+
}
1205+
}
1206+
11991207
CastKind::ClosureFnPointer |
1200-
CastKind::UnsafeFnPointer |
12011208
CastKind::Misc |
12021209
CastKind::Unsize => {}
1203-
12041210
}
12051211
}
12061212

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+
15+
fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
16+
// Here the NLL checker must relate the types in `f` to the types
17+
// in `g`. These are related via the `UnsafeFnPointer` cast.
18+
let g: unsafe fn(_) -> _ = f;
19+
//~^ WARNING not reporting region error due to -Znll
20+
unsafe { g(input) }
21+
//~^ ERROR free region `'_#1r` does not outlive free region `'static`
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)