1 // Copyright 2016 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.
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.
11 // Check that coercions can unify if-else, match arms and array elements.
13 // Try to construct if-else chains, matches and arrays out of given expressions.
15 ($last
:expr $
(, $rest
:expr
)+) => {
16 // Last expression comes first because of whacky ifs and matches.
17 let _
= $
(if false { $rest }
)else+ else { $last }
;
19 let _
= match 0 { $(_ if false => $rest,)+ _ => $last }
;
21 let _
= [$
($rest
,)+ $last
];
25 // Check all non-uniform cases of 2 and 3 expressions of 2 types.
27 ($a
:expr
, $b
:expr
) => {
41 // Check all non-uniform cases of 2 and 3 expressions of 3 types.
43 ($a
:expr
, $b
:expr
, $c
:expr
) => {
44 // Delegate to check2 for cases where a type repeats.
49 // Check the remaining cases, i.e. permutations of ($a, $b, $c).
59 use std
::mem
::size_of
;
65 check3
!(foo
, bar
, foo
as fn());
66 check3
!(size_of
::<u8>, size_of
::<u16>, size_of
::<usize> as fn() -> usize);
68 let s
= String
::from("bar");
72 let v
= vec
![1, 2, 3];
75 // Make sure in-array coercion still works.
76 let _
= [("a", Default
::default()), (Default
::default(), "b"), (&s
, &s
)];