diff options
| author | Adam Perry <adam.n.perry@gmail.com> | 2019-10-09 06:20:23 -0700 |
|---|---|---|
| committer | Adam Perry <adam.n.perry@gmail.com> | 2019-10-09 20:19:09 -0700 |
| commit | b8414c13abf9dc994f9c0dccee848a8b0fb1b061 (patch) | |
| tree | c3cd04665d799959a41cc43d3763fa66347b37ba | |
| parent | 01327384370b81e3a155dc70a2533935c4495db8 (diff) | |
| download | rust-b8414c13abf9dc994f9c0dccee848a8b0fb1b061.tar.gz rust-b8414c13abf9dc994f9c0dccee848a8b0fb1b061.zip | |
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.
| -rw-r--r-- | src/librustc/ty/instance.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/rfc-2091-track-caller/taking-fn-pointer.stderr | 21 |
3 files changed, 39 insertions, 2 deletions
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 471bd163754..18b625984e1 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -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), diff --git a/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs b/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs new file mode 100644 index 00000000000..df3893f2a6a --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs @@ -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); +} \ No newline at end of file diff --git a/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.stderr b/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.stderr new file mode 100644 index 00000000000..fb625ae116e --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.stderr @@ -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 + |
