add more track_caller tests

This commit is contained in:
Ralf Jung 2022-07-22 10:34:52 -04:00
parent 1cb9ccb284
commit 1787c731ab

View File

@ -66,6 +66,27 @@ fn test_trait_obj() {
assert_eq!(location.column(), 28);
}
fn test_trait_obj2() {
// track_caller on the impl but not the trait.
pub trait Foo {
fn foo(&self) -> &'static Location<'static>;
}
struct Bar;
impl Foo for Bar {
#[track_caller]
fn foo(&self) -> &'static Location<'static> {
std::panic::Location::caller()
}
}
let expected_line = line!() - 4; // the `fn` signature above
let f = &Bar as &dyn Foo;
let loc = f.foo(); // trait doesn't track, so we don't point at this call site
assert_eq!(loc.file(), file!());
assert_eq!(loc.line(), expected_line);
}
fn main() {
let location = Location::caller();
let expected_line = line!() - 1;
@ -105,4 +126,5 @@ fn main() {
test_fn_ptr();
test_trait_obj();
test_trait_obj2();
}