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.
12 // Check that coercions can unify if-else, match arms and array elements.
14 // Try to construct if-else chains, matches and arrays out of given expressions.
16 ($last:expr $(, $rest:expr)+) => {
17 // Last expression comes first because of whacky ifs and matches.
18 let _ = $(if false { $rest })else+ else { $last };
20 let _ = match 0 { $(_ if false => $rest,)+ _ => $last };
22 let _ = [$($rest,)+ $last];
26 // Check all non-uniform cases of 2 and 3 expressions of 2 types.
28 ($a:expr, $b:expr) => {
42 // Check all non-uniform cases of 2 and 3 expressions of 3 types.
44 ($a:expr, $b:expr, $c:expr) => {
45 // Delegate to check2 for cases where a type repeats.
50 // Check the remaining cases, i.e., permutations of ($a, $b, $c).
60 use std::mem::size_of;
66 check3!(foo, bar, foo as fn());
67 check3!(size_of::<u8>, size_of::<u16>, size_of::<usize> as fn() -> usize);
69 let s = String::from("bar");
73 let v = vec![1, 2, 3];
76 // Make sure in-array coercion still works.
77 let _ = [("a", Default::default()), (Default::default(), "b"), (&s, &s)];