]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce/coerce-unsize-subtype.rs
Migrate `src/test/ui/run-pass/*` back to `src/test/run-pass/`.
[rust.git] / src / test / run-pass / coerce / coerce-unsize-subtype.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // run-pass
12 // pretty-expanded FIXME #23616
13
14 use std::rc::Rc;
15
16 fn lub_short<'a, T>(_: &[&'a T], _: &[&'a T]) {}
17
18 // The two arguments are a subtype of their LUB, after coercion.
19 fn long_and_short<'a, T>(xs: &[&'static T; 1], ys: &[&'a T; 1]) {
20     lub_short(xs, ys);
21 }
22
23 // The argument coerces to a subtype of the return type.
24 fn long_to_short<'a, 'b, T>(xs: &'b [&'static T; 1]) -> &'b [&'a T] {
25     xs
26 }
27
28 // Rc<T> is covariant over T just like &T.
29 fn long_to_short_rc<'a, T>(xs: Rc<[&'static T; 1]>) -> Rc<[&'a T]> {
30     xs
31 }
32
33 // LUB-coercion (if-else/match/array) coerces `xs: &'b [&'static T: N]`
34 // to a subtype of the LUB of `xs` and `ys` (i.e. `&'b [&'a T]`),
35 // regardless of the order they appear (in if-else/match/array).
36 fn long_and_short_lub1<'a, 'b, T>(xs: &'b [&'static T; 1], ys: &'b [&'a T]) {
37     let _order1 = [xs, ys];
38     let _order2 = [ys, xs];
39 }
40
41 // LUB-coercion should also have the exact same effect when `&'b [&'a T; N]`
42 // needs to be coerced, i.e. the resulting type is not &'b [&'static T], but
43 // rather the `&'b [&'a T]` LUB.
44 fn long_and_short_lub2<'a, 'b, T>(xs: &'b [&'static T], ys: &'b [&'a T; 1]) {
45     let _order1 = [xs, ys];
46     let _order2 = [ys, xs];
47 }
48
49 fn main() {}