]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/impl-trait/equality.rs
New upstream version 1.17.0+dfsg1
[rustc.git] / src / test / run-pass / impl-trait / equality.rs
CommitLineData
5bcae85e
SL
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.
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#![feature(conservative_impl_trait, specialization)]
12
13trait Foo: std::fmt::Debug + Eq {}
14
15impl<T: std::fmt::Debug + Eq> Foo for T {}
16
17fn hide<T: Foo>(x: T) -> impl Foo {
18 x
19}
20
21trait Leak<T>: Sized {
22 fn leak(self) -> T;
23}
24impl<T, U> Leak<T> for U {
25 default fn leak(self) -> T { panic!("type mismatch") }
26}
27impl<T> Leak<T> for T {
28 fn leak(self) -> T { self }
29}
30
8bb4bdeb
XL
31trait CheckIfSend: Sized {
32 type T: Default;
33 fn check(self) -> Self::T { Default::default() }
34}
35impl<T> CheckIfSend for T {
36 default type T = ();
37}
38impl<T: Send> CheckIfSend for T {
39 type T = bool;
40}
41
5bcae85e
SL
42fn lucky_seven() -> impl Fn(usize) -> u8 {
43 let a = [1, 2, 3, 4, 5, 6, 7];
44 move |i| a[i]
45}
46
47fn main() {
48 assert_eq!(hide(42), hide(42));
49
50 assert_eq!(std::mem::size_of_val(&hide([0_u8; 5])), 5);
51 assert_eq!(std::mem::size_of_val(&lucky_seven()), 7);
52
53 assert_eq!(Leak::<i32>::leak(hide(5_i32)), 5_i32);
8bb4bdeb
XL
54
55 assert_eq!(CheckIfSend::check(hide(0_i32)), false);
5bcae85e 56}