]>
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 | // | |
5 | // FIXME(#73154) Skip for compare-mode because the pure NLL checker accepts this | |
6 | // test. (Note that it still errors in old-lub-glb-hr-noteq1.rs). What happens | |
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 | |
10 | // relationship, and that holds. | |
11 | // | |
12 | // ignore-compare-mode-nll | |
94222f64 | 13 | // ignore-compare-mode-polonius |
f035d41b XL |
14 | |
15 | fn foo(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { | |
16 | // The two types above are not equivalent. With the older LUB/GLB | |
17 | // algorithm, this may have worked (I don't remember), but now it | |
18 | // doesn't because we require equality. | |
19 | let z = match 22 { | |
20 | 0 => y, | |
21 | _ => x, //~ ERROR `match` arms have incompatible types | |
22 | }; | |
23 | } | |
24 | ||
25 | fn foo_cast(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { | |
26 | // But we can *upcast* explicitly the type of `x` and figure | |
27 | // things out: | |
28 | let z = match 22 { | |
29 | 0 => x as for<'a> fn(&'a u8, &'a u8) -> &'a u8, | |
30 | _ => y, | |
31 | }; | |
32 | } | |
33 | ||
34 | fn main() {} |