Rollup merge of #68302 - anp:caller-fn-ptr, r=eddyb,oli-obk

Fix #[track_caller] and function pointers

Starting with failing tests, fix the miscompilation and ICE caused by `ReifyShim` bug.

Fixes #68178.
This commit is contained in:
Yuki Okushi 2020-01-21 07:32:45 +09:00 committed by GitHub
commit 8d2bac8dff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 31 deletions

View file

@ -0,0 +1,19 @@
// run-pass
#![feature(track_caller)]
fn pass_to_ptr_call<T>(f: fn(T), x: T) {
f(x);
}
#[track_caller]
fn tracked_unit(_: ()) {
let expected_line = line!() - 1;
let location = std::panic::Location::caller();
assert_eq!(location.file(), file!());
assert_eq!(location.line(), expected_line, "call shims report location as fn definition");
}
fn main() {
pass_to_ptr_call(tracked_unit, ());
}

View file

@ -0,0 +1,19 @@
// run-pass
#![feature(track_caller)]
fn ptr_call(f: fn()) {
f();
}
#[track_caller]
fn tracked() {
let expected_line = line!() - 1;
let location = std::panic::Location::caller();
assert_eq!(location.file(), file!());
assert_eq!(location.line(), expected_line, "call shims report location as fn definition");
}
fn main() {
ptr_call(tracked);
}