]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/issue-83538-tainted-cache-after-cycle.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / traits / issue-83538-tainted-cache-after-cycle.rs
1 // Regression test for issue #83538. The problem here is that we have
2 // two cycles:
3 //
4 // * `Ty` embeds `Box<Ty>` indirectly, which depends on `Global: 'static`, which is OkModuloRegions.
5 // * But `Ty` also references `First`, which has a cycle on itself. That should just be `Ok`.
6 //
7 // But our caching mechanism was blending both cycles and giving the incorrect result.
8
9 #![feature(rustc_attrs)]
10 #![allow(bad_style)]
11
12 struct First {
13     b: Vec<First>,
14 }
15
16 pub struct Second {
17     d: Vec<First>,
18 }
19
20 struct Third<'a, f> {
21     g: Vec<(f, &'a f)>,
22 }
23
24 enum Ty {
25     j(Fourth, Fifth, Sixth),
26 }
27
28 struct Fourth {
29     o: Vec<Ty>,
30 }
31
32 struct Fifth {
33     bounds: First,
34 }
35
36 struct Sixth {
37     p: Box<Ty>,
38 }
39
40 #[rustc_evaluate_where_clauses]
41 fn forward<'a>()
42 where
43     Vec<First>: Unpin,
44     Third<'a, Ty>: Unpin,
45 {
46 }
47
48 #[rustc_evaluate_where_clauses]
49 fn reverse<'a>()
50 where
51     Third<'a, Ty>: Unpin,
52     Vec<First>: Unpin,
53 {
54 }
55
56 fn main() {
57     // Key is that Vec<First> is "ok" and Third<'_, Ty> is "ok modulo regions":
58
59     forward();
60     //~^ ERROR evaluate(Binder(TraitPredicate(<std::vec::Vec<First> as std::marker::Unpin>, polarity:Positive), [])) = Ok(EvaluatedToOk)
61     //~| ERROR evaluate(Binder(TraitPredicate(<Third<'_, Ty> as std::marker::Unpin>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions)
62
63     reverse();
64     //~^ ERROR evaluate(Binder(TraitPredicate(<std::vec::Vec<First> as std::marker::Unpin>, polarity:Positive), [])) = Ok(EvaluatedToOk)
65     //~| ERROR evaluate(Binder(TraitPredicate(<Third<'_, Ty> as std::marker::Unpin>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions)
66 }