]> git.proxmox.com Git - rustc.git/blame - src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / rfc-2091-track-caller / tracked-fn-ptr-with-arg.rs
CommitLineData
dfeec247 1// run-pass
29967ef6 2// revisions: default mir-opt
6a06907d 3//[mir-opt] compile-flags: -Zmir-opt-level=4
dfeec247 4
dfeec247
XL
5fn pass_to_ptr_call<T>(f: fn(T), x: T) {
6 f(x);
7}
8
9#[track_caller]
10fn 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
ba9703b0
XL
17trait Trait {
18 fn trait_tracked_unit(_: ());
19}
20
21impl 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
31trait 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
41impl TrackedTrait for () {}
42
43trait BlanketTrackedTrait {
44 #[track_caller]
45 fn tracked_blanket(_: ());
46}
47
48impl 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
dfeec247
XL
57fn main() {
58 pass_to_ptr_call(tracked_unit, ());
ba9703b0
XL
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, ());
dfeec247 62}