]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs
Auto merge of #106143 - matthiaskrgr:rollup-3kpy1dc, r=matthiaskrgr
[rust.git] / src / test / ui / rfc-2091-track-caller / tracked-fn-ptr-with-arg.rs
1 // run-pass
2 // revisions: default mir-opt
3 //[mir-opt] compile-flags: -Zmir-opt-level=4
4
5 fn pass_to_ptr_call<T>(f: fn(T), x: T) {
6     f(x);
7 }
8
9 #[track_caller]
10 fn tracked_unit(_: ()) {
11     let expected_line = line!() - 1;
12     let location = std::panic::Location::caller();
13     assert_eq!(location.file(), file!());
14     assert_eq!(location.line(), expected_line, "call shims report location as fn definition");
15 }
16
17 trait Trait {
18     fn trait_tracked_unit(_: ());
19 }
20
21 impl Trait for () {
22     #[track_caller]
23     fn trait_tracked_unit(_: ()) {
24         let expected_line = line!() - 1;
25         let location = std::panic::Location::caller();
26         assert_eq!(location.file(), file!());
27         assert_eq!(location.line(), expected_line, "call shims report location as fn definition");
28     }
29 }
30
31 trait TrackedTrait {
32     #[track_caller]
33     fn trait_tracked_unit_default(_: ()) {
34         let expected_line = line!() - 1;
35         let location = std::panic::Location::caller();
36         assert_eq!(location.file(), file!());
37         assert_eq!(location.line(), expected_line, "call shims report location as fn definition");
38     }
39 }
40
41 impl TrackedTrait for () {}
42
43 trait BlanketTrackedTrait {
44     #[track_caller]
45     fn tracked_blanket(_: ());
46 }
47
48 impl BlanketTrackedTrait for () {
49     fn tracked_blanket(_: ()) {
50         let expected_line = line!() - 1;
51         let location = std::panic::Location::caller();
52         assert_eq!(location.file(), file!());
53         assert_eq!(location.line(), expected_line, "call shims report location as fn definition");
54     }
55 }
56
57 fn main() {
58     pass_to_ptr_call(tracked_unit, ());
59     pass_to_ptr_call(<() as Trait>::trait_tracked_unit, ());
60     pass_to_ptr_call(<() as TrackedTrait>::trait_tracked_unit_default, ());
61     pass_to_ptr_call(<() as BlanketTrackedTrait>::tracked_blanket, ());
62 }