Skip to content

Commit e218da4

Browse files
committed
Test cleanups to match #[track_caller] in panic!.
* Removes unnecessary feature flag from track_caller test. * Tests of panic internals no longer need to explicitly construct Location. * Add #![warn(const_err)] to retain-never-const per @oli-obk. * Add track_caller test with diverging function.
1 parent eaccda0 commit e218da4

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

src/test/mir-opt/retain-never-const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#![feature(const_panic)]
88
#![feature(never_type)]
9+
#![warn(const_err)]
910

1011
struct PrintName<T>(T);
1112

src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//[thin]compile-flags: -C lto=thin
2323
//[fat]compile-flags: -C lto=fat
2424

25-
#![feature(core_panic, panic_internals)]
25+
#![feature(core_panic)]
2626

2727
// (For some reason, reproducing the LTO issue requires pulling in std
2828
// explicitly this way.)
@@ -50,9 +50,7 @@ fn main() {
5050
}
5151

5252
let _guard = Droppable;
53-
let s = "issue-64655-allow-unwind-when-calling-panic-directly.rs";
54-
let location = core::panic::Location::internal_constructor(s, 17, 4);
55-
core::panicking::panic("???", &location);
53+
core::panicking::panic("???");
5654
});
5755

5856
let wait = handle.join();

src/test/ui/rfc-2091-track-caller/caller-location-intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
#[inline(never)]
66
#[track_caller]
7-
fn defeat_const_prop() -> &'static core::panic::Location<'static> {
7+
fn codegen_caller_loc() -> &'static core::panic::Location<'static> {
88
core::panic::Location::caller()
99
}
1010

1111
macro_rules! caller_location_from_macro {
12-
() => (defeat_const_prop());
12+
() => (codegen_caller_loc());
1313
}
1414

1515
fn main() {
16-
let loc = defeat_const_prop();
16+
let loc = codegen_caller_loc();
1717
assert_eq!(loc.file(), file!());
1818
assert_eq!(loc.line(), 16);
1919
assert_eq!(loc.column(), 15);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-fail
2+
3+
//! This test ensures that `#[track_caller]` can be applied directly to diverging functions, as
4+
//! the tracking issue says: https://github.com/rust-lang/rust/issues/47809#issue-292138490.
5+
//! Because the annotated function must diverge and a panic keeps that faster than an infinite loop,
6+
//! we don't inspect the location returned -- it would be difficult to distinguish between the
7+
//! explicit panic and a failed assertion. That it compiles and runs is enough for this one.
8+
9+
#![feature(track_caller)]
10+
11+
#[track_caller]
12+
fn doesnt_return() -> ! {
13+
let _location = core::panic::Location::caller();
14+
panic!("huzzah");
15+
}
16+
17+
fn main() {
18+
doesnt_return();
19+
}

src/test/ui/rfc-2091-track-caller/track-caller-attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22

3-
#![feature(const_fn, track_caller)]
3+
#![feature(track_caller)]
44

55
use std::panic::Location;
66

0 commit comments

Comments
 (0)