Skip to content

Commit b8414c1

Browse files
committed
Return ReifyShim from Instance::resolve_for_fn_ptr when track_caller present.
This ICEs in MIR currently, which I think is to be expected since none of the MIR plumbing is set up. I added a test which confirms that the shim is being used for reifying a track_caller function.
1 parent 0132738 commit b8414c1

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/librustc/ty/instance.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// use crate::hir::CodegenFnAttrFlags;
1+
use crate::hir::CodegenFnAttrFlags;
22
use crate::hir::Unsafety;
33
use crate::hir::def::Namespace;
44
use crate::hir::def_id::DefId;
@@ -305,7 +305,7 @@ impl<'tcx> Instance<'tcx> {
305305
substs: SubstsRef<'tcx>,
306306
) -> Option<Instance<'tcx>> {
307307
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
308-
if false {
308+
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER) {
309309
debug!(" => fn pointer created for function with #[track_caller]");
310310
Some(Instance {
311311
def: InstanceDef::ReifyShim(def_id),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// failure-status: 101
2+
// normalize-stderr-test "note: rustc 1.* running on .*" -> "note: rustc VERSION running on TARGET"
3+
// normalize-stderr-test "note: compiler flags: .*" -> "note: compiler flags: FLAGS"
4+
5+
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete
6+
7+
#[track_caller]
8+
fn f() {}
9+
10+
fn call_it(x: fn()) {
11+
x();
12+
}
13+
14+
fn main() {
15+
call_it(f);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
warning: the feature `track_caller` is incomplete and may cause the compiler to crash
2+
--> $DIR/taking-fn-pointer.rs:5:12
3+
|
4+
LL | #![feature(track_caller)]
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', $SRC_DIR/libcore/slice/mod.rs:LL:COL
10+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
11+
12+
error: internal compiler error: unexpected panic
13+
14+
note: the compiler unexpectedly panicked. this is a bug.
15+
16+
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
17+
18+
note: rustc VERSION running on TARGET
19+
20+
note: compiler flags: FLAGS
21+

0 commit comments

Comments
 (0)