]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/project-modulo-regions.rs
Rollup merge of #100953 - joshtriplett:write-docs, r=Mark-Simulacrum
[rust.git] / src / test / ui / traits / project-modulo-regions.rs
1 // revisions: with_clause without_clause
2 // Tests that `EvaluatedToOkModuloRegions` from a projection sub-obligation
3 // is correctly propagated
4
5 #![feature(rustc_attrs)]
6
7 trait MyTrait {
8     type Assoc;
9 }
10
11 struct MyStruct;
12
13 impl MyTrait for MyStruct {
14     // Evaluating this projection will result in `EvaluatedToOkModuloRegions`
15     // (when `with_clause` is enabled)
16     type Assoc = <Bar as MyTrait>::Assoc;
17 }
18
19 struct Bar;
20
21 // The `where` clause on this impl will cause us to produce `EvaluatedToOkModuloRegions`
22 // when evaluating a projection involving this impl
23 #[cfg(with_clause)]
24 impl MyTrait for Bar where for<'b> &'b (): 'b {
25     type Assoc = bool;
26 }
27
28 // This impl tests that the `EvaluatedToOkModuoRegions` result that we get
29 // is really due to the `where` clause on the `with_clause` impl
30 #[cfg(without_clause)]
31 impl MyTrait for Bar {
32     type Assoc = bool;
33 }
34
35 // The implementation of `#[rustc_evaluate_where_clauses]` doesn't perform
36 // normalization, so we need to place the projection predicate behind a normal
37 // trait predicate
38 struct Helper {}
39 trait HelperTrait {}
40 impl HelperTrait for Helper where <MyStruct as MyTrait>::Assoc: Sized {}
41
42 // Evaluating this 'where' clause will (recursively) end up evaluating
43 // `for<'b> &'b (): 'b`, which will produce `EvaluatedToOkModuloRegions`
44 #[rustc_evaluate_where_clauses]
45 fn test(val: MyStruct) where Helper: HelperTrait  {
46     panic!()
47 }
48
49 fn foo(val: MyStruct) {
50     test(val);
51     //[with_clause]~^     ERROR evaluate(Binder(TraitPredicate(<Helper as HelperTrait>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions)
52     //[without_clause]~^^ ERROR evaluate(Binder(TraitPredicate(<Helper as HelperTrait>, polarity:Positive), [])) = Ok(EvaluatedToOk)
53 }
54
55 fn main() {}