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.
This commit is contained in:
Adam Perry 2019-10-09 06:20:23 -07:00
parent 0132738437
commit b8414c13ab
3 changed files with 39 additions and 2 deletions

View File

@ -1,4 +1,4 @@
// use crate::hir::CodegenFnAttrFlags;
use crate::hir::CodegenFnAttrFlags;
use crate::hir::Unsafety;
use crate::hir::def::Namespace;
use crate::hir::def_id::DefId;
@ -305,7 +305,7 @@ impl<'tcx> Instance<'tcx> {
substs: SubstsRef<'tcx>,
) -> Option<Instance<'tcx>> {
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
if false {
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER) {
debug!(" => fn pointer created for function with #[track_caller]");
Some(Instance {
def: InstanceDef::ReifyShim(def_id),

View File

@ -0,0 +1,16 @@
// failure-status: 101
// normalize-stderr-test "note: rustc 1.* running on .*" -> "note: rustc VERSION running on TARGET"
// normalize-stderr-test "note: compiler flags: .*" -> "note: compiler flags: FLAGS"
#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete
#[track_caller]
fn f() {}
fn call_it(x: fn()) {
x();
}
fn main() {
call_it(f);
}

View File

@ -0,0 +1,21 @@
warning: the feature `track_caller` is incomplete and may cause the compiler to crash
--> $DIR/taking-fn-pointer.rs:5:12
|
LL | #![feature(track_caller)]
| ^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
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
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc VERSION running on TARGET
note: compiler flags: FLAGS