]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/cycle-cache-err-60010.rs
Auto merge of #84959 - camsteffen:lint-suggest-group, r=estebank
[rust.git] / src / test / ui / traits / cycle-cache-err-60010.rs
1 // Test that we properly detect the cycle amongst the traits
2 // here and report an error.
3
4 use std::panic::RefUnwindSafe;
5
6 trait Database {
7     type Storage;
8 }
9 trait HasQueryGroup {}
10 trait Query<DB> {
11     type Data;
12 }
13 trait SourceDatabase {
14     fn parse(&self) {
15         loop {}
16     }
17 }
18
19 struct ParseQuery;
20 struct RootDatabase {
21     _runtime: Runtime<RootDatabase>,
22 }
23 struct Runtime<DB: Database> {
24     _storage: Box<DB::Storage>,
25 }
26 struct SalsaStorage {
27     _parse: <ParseQuery as Query<RootDatabase>>::Data,
28 }
29
30 impl Database for RootDatabase {
31     // This would also be an error if we didn't abort compilation on the error
32     // above.
33     type Storage = SalsaStorage;
34 }
35 impl HasQueryGroup for RootDatabase {}
36 impl<DB> Query<DB> for ParseQuery
37 where
38     DB: SourceDatabase,
39     DB: Database,
40 {
41     type Data = RootDatabase;
42 }
43 impl<T> SourceDatabase for T
44 where
45     T: RefUnwindSafe,
46     T: HasQueryGroup,
47 {
48 }
49
50 pub(crate) fn goto_implementation(db: &RootDatabase) -> u32 {
51     // This is not satisfied:
52     //
53     // - `RootDatabase: SourceDatabase`
54     //   - requires `RootDatabase: RefUnwindSafe` + `RootDatabase: HasQueryGroup`
55     // - `RootDatabase: RefUnwindSafe`
56     //   - requires `Runtime<RootDatabase>: RefUnwindSafe`
57     // - `Runtime<RootDatabase>: RefUnwindSafe`
58     //   - requires `DB::Storage: RefUnwindSafe` (`SalsaStorage: RefUnwindSafe`)
59     // - `SalsaStorage: RefUnwindSafe`
60     //    - requires `<ParseQuery as Query<RootDatabase>>::Data: RefUnwindSafe`,
61     //      which means `ParseQuery: Query<RootDatabase>`
62     // - `ParseQuery: Query<RootDatabase>`
63     //    - requires `RootDatabase: SourceDatabase`,
64     // - `RootDatabase: SourceDatabase` is already on the stack, so we have a
65     //   cycle with non-coinductive participants
66     //
67     // we used to fail to report an error here because we got the
68     // caching wrong.
69     SourceDatabase::parse(db);
70     //~^ ERROR overflow
71     22
72 }
73
74 fn main() {}