]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/cycle-cache-err-60010.rs
Report cycle error using 'deepest' obligation in the cycle
[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     //~^ ERROR overflow
29 }
30
31 impl Database for RootDatabase {
32     // This would also be an error if we didn't abort compilation on the error
33     // above.
34     type Storage = SalsaStorage;
35 }
36 impl HasQueryGroup for RootDatabase {}
37 impl<DB> Query<DB> for ParseQuery
38 where
39     DB: SourceDatabase,
40     DB: Database,
41 {
42     type Data = RootDatabase;
43 }
44 impl<T> SourceDatabase for T
45 where
46     T: RefUnwindSafe,
47     T: HasQueryGroup,
48 {
49 }
50
51 pub(crate) fn goto_implementation(db: &RootDatabase) -> u32 {
52     // This is not satisfied:
53     //
54     // - `RootDatabase: SourceDatabase`
55     //   - requires `RootDatabase: RefUnwindSafe` + `RootDatabase: HasQueryGroup`
56     // - `RootDatabase: RefUnwindSafe`
57     //   - requires `Runtime<RootDatabase>: RefUnwindSafe`
58     // - `Runtime<RootDatabase>: RefUnwindSafe`
59     //   - requires `DB::Storage: RefUnwindSafe` (`SalsaStorage: RefUnwindSafe`)
60     // - `SalsaStorage: RefUnwindSafe`
61     //    - requires `<ParseQuery as Query<RootDatabase>>::Data: RefUnwindSafe`,
62     //      which means `ParseQuery: Query<RootDatabase>`
63     // - `ParseQuery: Query<RootDatabase>`
64     //    - requires `RootDatabase: SourceDatabase`,
65     // - `RootDatabase: SourceDatabase` is already on the stack, so we have a
66     //   cycle with non-coinductive participants
67     //
68     // we used to fail to report an error here because we got the
69     // caching wrong.
70     SourceDatabase::parse(db);
71     22
72 }
73
74 fn main() {}