File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ impl<'a> Location<'a> {
83
83
#[ stable( feature = "track_caller" , since = "1.46.0" ) ]
84
84
#[ rustc_const_unstable( feature = "const_caller_location" , issue = "76156" ) ]
85
85
#[ track_caller]
86
+ #[ inline( always) ] // Mark as inline so that the call gets optimized away.
86
87
pub const fn caller ( ) -> & ' static Location < ' static > {
87
88
crate :: intrinsics:: caller_location ( )
88
89
}
Original file line number Diff line number Diff line change
1
+ // This test makes sure that calls to std::panic::Location::caller()
2
+ // don't result in an actual function call. The caller location is
3
+ // known at compile time so the call can always be optimized away.
4
+
5
+ // compile-flags: -Copt-level=2
6
+
7
+ #![ crate_type = "lib" ]
8
+ #![ feature( bench_black_box) ]
9
+
10
+ // The first check makes sure that the caller location is used at all,
11
+ // i.e. that std::hint::black_box() works.
12
+ // CHECK: %0 = alloca %"core::panic::location::Location"*
13
+
14
+ // This check makes sure that no call to `std::panic::Location::caller()`
15
+ // is emitted. The sequence of characters is valid for both v0 and legacy
16
+ // mangling.
17
+ // CHECK-NOT: call {{.*}}8Location6caller
18
+
19
+ // CHECK: call void asm sideeffect {{.*}}(%"core::panic::location::Location"** nonnull %0)
20
+
21
+ #[ track_caller]
22
+ fn foo ( ) {
23
+ std:: hint:: black_box ( std:: panic:: Location :: caller ( ) ) ;
24
+ }
25
+
26
+ pub fn bar ( ) {
27
+ foo ( ) ;
28
+ }
You can’t perform that action at this time.
0 commit comments