Auto merge of #2418 - RalfJung:track, r=RalfJung
add more track_caller tests Suggested by `@eddyb`
This commit is contained in:
commit
963f08b702
@ -66,6 +66,27 @@ impl Tracked for u8 {}
|
||||
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user