]> git.lizzy.rs Git - rust.git/blob - tests/ui/associated-types/normalize-cycle-in-eval.rs
Auto merge of #103659 - clubby789:improve-partialord-derive, r=nagisa
[rust.git] / tests / ui / associated-types / normalize-cycle-in-eval.rs
1 // regression test for #74868
2
3 // check-pass
4
5 trait BoxedDsl<'a> {
6     type Output;
7 }
8
9 impl<'a, T> BoxedDsl<'a> for T
10 where
11     T: BoxedDsl<'a>,
12 {
13     type Output = <T as BoxedDsl<'a>>::Output;
14 }
15
16 // Showing this trait is wf requires proving
17 // Self: HandleUpdate
18 //
19 // The impl below is a candidate for this projection, as well as the `Self:
20 // HandleUpdate` bound in the environment.
21 // We evaluate both candidates to see if we need to consider both applicable.
22 // Evaluating the impl candidate requires evaluating
23 // <T as BoxedDsl<'static>>::Output == ()
24 // The above impl cause normalizing the above type normalize to itself.
25 //
26 // This previously compiled because we would generate a new region
27 // variable each time around the cycle, and evaluation would eventually return
28 // `EvaluatedToErr` from the `Self: Sized` in the impl, which would in turn
29 // leave the bound as the only candidate.
30 //
31 // #73452 changed this so that region variables are canonicalized when we
32 // normalize, which means that the projection cycle is detected before
33 // evaluation returns EvaluatedToErr. The cycle resulted in an error being
34 // emitted immediately, causing this to fail to compile.
35 //
36 // To fix this, normalization doesn't directly emit errors when it finds a
37 // cycle, instead letting the caller handle it. This restores the original
38 // behavior.
39 trait HandleUpdate {}
40
41 impl<T> HandleUpdate for T where T: BoxedDsl<'static, Output = ()> {}
42
43 fn main() {}