]> git.proxmox.com Git - rustc.git/blob - tests/ui/coercion/coerce-unsize-subtype.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / coercion / coerce-unsize-subtype.rs
1 // run-pass
2 #![allow(dead_code)]
3 // pretty-expanded FIXME #23616
4
5 use std::rc::Rc;
6
7 fn lub_short<'a, T>(_: &[&'a T], _: &[&'a T]) {}
8
9 // The two arguments are a subtype of their LUB, after coercion.
10 fn long_and_short<'a, T>(xs: &[&'static T; 1], ys: &[&'a T; 1]) {
11 lub_short(xs, ys);
12 }
13
14 // The argument coerces to a subtype of the return type.
15 fn long_to_short<'a, 'b, T>(xs: &'b [&'static T; 1]) -> &'b [&'a T] {
16 xs
17 }
18
19 // Rc<T> is covariant over T just like &T.
20 fn long_to_short_rc<'a, T>(xs: Rc<[&'static T; 1]>) -> Rc<[&'a T]> {
21 xs
22 }
23
24 // LUB-coercion (if-else/match/array) coerces `xs: &'b [&'static T: N]`
25 // to a subtype of the LUB of `xs` and `ys` (i.e., `&'b [&'a T]`),
26 // regardless of the order they appear (in if-else/match/array).
27 fn long_and_short_lub1<'a, 'b, T>(xs: &'b [&'static T; 1], ys: &'b [&'a T]) {
28 let _order1 = [xs, ys];
29 let _order2 = [ys, xs];
30 }
31
32 // LUB-coercion should also have the exact same effect when `&'b [&'a T; N]`
33 // needs to be coerced, i.e., the resulting type is not &'b [&'static T], but
34 // rather the `&'b [&'a T]` LUB.
35 fn long_and_short_lub2<'a, 'b, T>(xs: &'b [&'static T], ys: &'b [&'a T; 1]) {
36 let _order1 = [xs, ys];
37 let _order2 = [ys, xs];
38 }
39
40 fn main() {}