Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustup for #[track_caller] trait object changes #1849

Merged
merged 1 commit into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c5e344f7747dbd7e7d4b209e3c480deb5979a56f
3982eb35cabe3a99194d768d34a92347967c3fa2
24 changes: 16 additions & 8 deletions tests/run-pass/track-caller-attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,31 @@ fn test_fn_ptr() {
fn test_trait_obj() {
trait Tracked {
#[track_caller]
fn handle(&self) { // `fn` here is what the `location` should point at.
let location = std::panic::Location::caller();
assert_eq!(location.file(), file!());
// we only call this via trait object, so the def site should *always* be returned
assert_eq!(location.line(), line!() - 4);
assert_eq!(location.column(), 9);
fn handle(&self) -> &'static Location<'static> {
std::panic::Location::caller()
}
}

impl Tracked for () {}
impl Tracked for u8 {}

// Test that we get the correct location
// even with a call through a trait object

let tracked: &dyn Tracked = &5u8;
tracked.handle();
let location = tracked.handle();
let expected_line = line!() - 1;
assert_eq!(location.file(), file!());
assert_eq!(location.line(), expected_line);
assert_eq!(location.column(), 28);

const TRACKED: &dyn Tracked = &();
TRACKED.handle();
let location = TRACKED.handle();
let expected_line = line!() - 1;
assert_eq!(location.file(), file!());
assert_eq!(location.line(), expected_line);
assert_eq!(location.column(), 28);

}

fn main() {
Expand Down