]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce/coerce-unsize-subtype.rs
Auto merge of #54626 - alexcrichton:dwarf-generics, r=michaelwoerister
[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 #![allow(dead_code)]
13 // pretty-expanded FIXME #23616
14
15 use std::rc::Rc;
16
17 fn lub_short<'a, T>(_: &[&'a T], _: &[&'a T]) {}
18
19 // The two arguments are a subtype of their LUB, after coercion.
20 fn long_and_short<'a, T>(xs: &[&'static T; 1], ys: &[&'a T; 1]) {
21     lub_short(xs, ys);
22 }
23
24 // The argument coerces to a subtype of the return type.
25 fn long_to_short<'a, 'b, T>(xs: &'b [&'static T; 1]) -> &'b [&'a T] {
26     xs
27 }
28
29 // Rc<T> is covariant over T just like &T.
30 fn long_to_short_rc<'a, T>(xs: Rc<[&'static T; 1]>) -> Rc<[&'a T]> {
31     xs
32 }
33
34 // LUB-coercion (if-else/match/array) coerces `xs: &'b [&'static T: N]`
35 // to a subtype of the LUB of `xs` and `ys` (i.e. `&'b [&'a T]`),
36 // regardless of the order they appear (in if-else/match/array).
37 fn long_and_short_lub1<'a, 'b, T>(xs: &'b [&'static T; 1], ys: &'b [&'a T]) {
38     let _order1 = [xs, ys];
39     let _order2 = [ys, xs];
40 }
41
42 // LUB-coercion should also have the exact same effect when `&'b [&'a T; N]`
43 // needs to be coerced, i.e. the resulting type is not &'b [&'static T], but
44 // rather the `&'b [&'a T]` LUB.
45 fn long_and_short_lub2<'a, 'b, T>(xs: &'b [&'static T], ys: &'b [&'a T; 1]) {
46     let _order1 = [xs, ys];
47     let _order2 = [ys, xs];
48 }
49
50 fn main() {}