]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dep-graph/dep-graph-struct-signature.rs
Auto merge of #55519 - fhartwig:hashmap-index-example, r=Centril
[rust.git] / src / test / ui / dep-graph / dep-graph-struct-signature.rs
1 // Test cases where a changing struct appears in the signature of fns
2 // and methods.
3
4 // compile-flags: -Z query-dep-graph
5
6 #![feature(rustc_attrs)]
7 #![allow(dead_code)]
8 #![allow(unused_variables)]
9
10 fn main() { }
11
12 #[rustc_if_this_changed]
13 struct WillChange {
14     x: u32,
15     y: u32
16 }
17
18 struct WontChange {
19     x: u32,
20     y: u32
21 }
22
23 // these are valid dependencies
24 mod signatures {
25     use WillChange;
26
27     #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path
28     #[rustc_then_this_would_need(AssociatedItems)] //~ ERROR no path
29     #[rustc_then_this_would_need(TraitDefOfItem)] //~ ERROR no path
30     trait Bar {
31         #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK
32         fn do_something(x: WillChange);
33     }
34
35     #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK
36     #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK
37     fn some_fn(x: WillChange) { }
38
39     #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK
40     #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK
41     fn new_foo(x: u32, y: u32) -> WillChange {
42         WillChange { x: x, y: y }
43     }
44
45     #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK
46     impl WillChange {
47         #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK
48         #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK
49         fn new(x: u32, y: u32) -> WillChange { loop { } }
50     }
51
52     #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK
53     impl WillChange {
54         #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK
55         #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK
56         fn method(&self, x: u32) { }
57     }
58
59     struct WillChanges {
60         #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK
61         x: WillChange,
62         #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK
63         y: WillChange
64     }
65
66     // The fields change, not the type itself.
67     #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path
68     fn indirect(x: WillChanges) { }
69 }
70
71 mod invalid_signatures {
72     use WontChange;
73
74     #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path
75     trait A {
76         #[rustc_then_this_would_need(FnSignature)] //~ ERROR no path
77         fn do_something_else_twice(x: WontChange);
78     }
79
80     #[rustc_then_this_would_need(FnSignature)] //~ ERROR no path
81     fn b(x: WontChange) { }
82
83     #[rustc_then_this_would_need(FnSignature)] //~ ERROR no path from `WillChange`
84     #[rustc_then_this_would_need(TypeckTables)] //~ ERROR no path from `WillChange`
85     fn c(x: u32) { }
86 }