]>
Commit | Line | Data |
---|---|---|
f035d41b XL |
1 | // Test taking the LUB of two function types that are not equatable but where |
2 | // one is more general than the other. Test the case where the more general type | |
3 | // (`x`) is the second match arm specifically. | |
4 | // | |
923072b8 FG |
5 | // FIXME(#73154) Pure NLL checker without leak check accepts this test. |
6 | // (Note that it still errors in old-lub-glb-hr-noteq1.rs). What happens | |
f035d41b XL |
7 | // is that, due to the ordering of the match arms, we pick the correct "more |
8 | // general" fn type, and we ignore the errors from the non-NLL type checker that | |
9 | // requires equality. The NLL type checker only requires a subtyping | |
923072b8 FG |
10 | // relationship, and that holds. To unblock landing NLL - and ensure that we can |
11 | // choose to make this always in error in the future - we perform the leak check | |
12 | // after coercing a function pointer. | |
13 | ||
14 | // revisions: leak noleak | |
15 | //[noleak] compile-flags: -Zno-leak-check | |
16 | ||
17 | //[noleak] check-pass | |
f035d41b XL |
18 | |
19 | fn foo(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { | |
20 | // The two types above are not equivalent. With the older LUB/GLB | |
21 | // algorithm, this may have worked (I don't remember), but now it | |
22 | // doesn't because we require equality. | |
23 | let z = match 22 { | |
24 | 0 => y, | |
923072b8 FG |
25 | _ => x, |
26 | //[leak]~^ ERROR `match` arms have incompatible types | |
f035d41b XL |
27 | }; |
28 | } | |
29 | ||
30 | fn foo_cast(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { | |
31 | // But we can *upcast* explicitly the type of `x` and figure | |
32 | // things out: | |
33 | let z = match 22 { | |
34 | 0 => x as for<'a> fn(&'a u8, &'a u8) -> &'a u8, | |
35 | _ => y, | |
36 | }; | |
37 | } | |
38 | ||
39 | fn main() {} |