Skip to content

Commit

Permalink
test: ensure #[track_caller] tests also test MIR inlining.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Oct 21, 2020
1 parent 6bc5eaf commit fb36440
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 12 deletions.
@@ -1,4 +1,6 @@
// run-pass
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=3

#[inline(never)]
#[track_caller]
Expand All @@ -13,13 +15,13 @@ macro_rules! caller_location_from_macro {
fn main() {
let loc = codegen_caller_loc();
assert_eq!(loc.file(), file!());
assert_eq!(loc.line(), 14);
assert_eq!(loc.line(), 16);
assert_eq!(loc.column(), 15);

// `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
// i.e. point to where the macro was invoked, instead of the macro itself.
let loc2 = caller_location_from_macro!();
assert_eq!(loc2.file(), file!());
assert_eq!(loc2.line(), 21);
assert_eq!(loc2.line(), 23);
assert_eq!(loc2.column(), 16);
}
10 changes: 6 additions & 4 deletions src/test/ui/rfc-2091-track-caller/const-caller-location.rs
@@ -1,4 +1,6 @@
// run-pass
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=3

#![feature(const_caller_location, const_fn)]

Expand All @@ -24,18 +26,18 @@ const fn contained() -> &'static Location<'static> {

fn main() {
assert_eq!(LOCATION.file(), file!());
assert_eq!(LOCATION.line(), 7);
assert_eq!(LOCATION.line(), 9);
assert_eq!(LOCATION.column(), 29);

assert_eq!(TRACKED.file(), file!());
assert_eq!(TRACKED.line(), 9);
assert_eq!(TRACKED.line(), 11);
assert_eq!(TRACKED.column(), 28);

assert_eq!(NESTED.file(), file!());
assert_eq!(NESTED.line(), 17);
assert_eq!(NESTED.line(), 19);
assert_eq!(NESTED.column(), 5);

assert_eq!(CONTAINED.file(), file!());
assert_eq!(CONTAINED.line(), 22);
assert_eq!(CONTAINED.line(), 24);
assert_eq!(CONTAINED.column(), 5);
}
6 changes: 4 additions & 2 deletions src/test/ui/rfc-2091-track-caller/intrinsic-wrapper.rs
@@ -1,4 +1,6 @@
// run-pass
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=3

macro_rules! caller_location_from_macro {
() => (core::panic::Location::caller());
Expand All @@ -7,13 +9,13 @@ macro_rules! caller_location_from_macro {
fn main() {
let loc = core::panic::Location::caller();
assert_eq!(loc.file(), file!());
assert_eq!(loc.line(), 8);
assert_eq!(loc.line(), 10);
assert_eq!(loc.column(), 15);

// `Location::caller()` in a macro should behave similarly to `file!` and `line!`,
// i.e. point to where the macro was invoked, instead of the macro itself.
let loc2 = caller_location_from_macro!();
assert_eq!(loc2.file(), file!());
assert_eq!(loc2.line(), 15);
assert_eq!(loc2.line(), 17);
assert_eq!(loc2.column(), 16);
}
3 changes: 3 additions & 0 deletions src/test/ui/rfc-2091-track-caller/pass.rs
@@ -1,4 +1,7 @@
// run-pass
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=3

#[track_caller]
fn f() {}

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/rfc-2091-track-caller/std-panic-locations.rs
@@ -1,5 +1,7 @@
// run-pass
// ignore-wasm32-bare compiled with panic=abort by default
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=3

#![feature(option_expect_none, option_unwrap_none)]
#![allow(unconditional_panic)]
Expand Down
10 changes: 6 additions & 4 deletions src/test/ui/rfc-2091-track-caller/track-caller-attribute.rs
@@ -1,4 +1,6 @@
// run-pass
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=3

use std::panic::Location;

Expand All @@ -18,21 +20,21 @@ fn nested_tracked() -> &'static Location<'static> {
fn main() {
let location = Location::caller();
assert_eq!(location.file(), file!());
assert_eq!(location.line(), 19);
assert_eq!(location.line(), 21);
assert_eq!(location.column(), 20);

let tracked = tracked();
assert_eq!(tracked.file(), file!());
assert_eq!(tracked.line(), 24);
assert_eq!(tracked.line(), 26);
assert_eq!(tracked.column(), 19);

let nested = nested_intrinsic();
assert_eq!(nested.file(), file!());
assert_eq!(nested.line(), 11);
assert_eq!(nested.line(), 13);
assert_eq!(nested.column(), 5);

let contained = nested_tracked();
assert_eq!(contained.file(), file!());
assert_eq!(contained.line(), 15);
assert_eq!(contained.line(), 17);
assert_eq!(contained.column(), 5);
}
2 changes: 2 additions & 0 deletions src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs
@@ -1,4 +1,6 @@
// run-pass
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=3

fn pass_to_ptr_call<T>(f: fn(T), x: T) {
f(x);
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs
@@ -1,4 +1,6 @@
// run-pass
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=3

fn ptr_call(f: fn()) {
f();
Expand Down

0 comments on commit fb36440

Please sign in to comment.