Skip to content

Commit 14700e5

Browse files
spastorinonikomatsakis
authored andcommitted
Mir typeck Cast for ClosureFnPtr value
1 parent ae035cb commit 14700e5

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/librustc_mir/transform/type_check.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,20 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11961196
}
11971197
}
11981198

1199+
CastKind::ClosureFnPointer => {
1200+
let sig = match op.ty(mir, tcx).sty {
1201+
ty::TyClosure(def_id, substs) => {
1202+
substs.closure_sig_ty(def_id, tcx).fn_sig(tcx)
1203+
}
1204+
_ => bug!(),
1205+
};
1206+
let ty_fn_ptr_from = tcx.coerce_closure_fn_ty(sig);
1207+
1208+
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.at_self()) {
1209+
span_mirbug!(self, "", "casting {:?}", terr);
1210+
}
1211+
}
1212+
11991213
CastKind::UnsafeFnPointer => {
12001214
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(op.ty(mir, tcx).fn_sig(tcx));
12011215

@@ -1204,9 +1218,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12041218
}
12051219
}
12061220

1207-
CastKind::ClosureFnPointer |
1208-
CastKind::Misc |
1209-
CastKind::Unsize => {}
1221+
CastKind::Misc | CastKind::Unsize => {}
12101222
}
12111223
}
12121224

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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, 'b>() -> fn(&'a u32, &'b u32) -> &'a u32 {
16+
let g: fn(_, _) -> _ = |_x, y| y;
17+
g
18+
//~^ WARNING not reporting region error due to -Znll
19+
//~| ERROR free region `'b` does not outlive free region `'a`
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)