]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/trait-coercion.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / trait-coercion.rs
CommitLineData
223e47cc
LB
1// Copyright 2013 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
1a4d82fc 11#![allow(unknown_features)]
c34b1796 12#![feature(box_syntax, old_io, io)]
970d7e83 13
c34b1796 14use std::io::{self, Write};
1a4d82fc
JJ
15
16trait Trait {
17 fn f(&self);
970d7e83
LB
18}
19
c34b1796 20#[derive(Copy, Clone)]
1a4d82fc 21struct Struct {
c34b1796
AL
22 x: isize,
23 y: isize,
970d7e83
LB
24}
25
1a4d82fc
JJ
26impl Trait for Struct {
27 fn f(&self) {
28 println!("Hi!");
970d7e83
LB
29 }
30}
31
c34b1796
AL
32fn foo(mut a: Box<Write>) {}
33
34// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
1a4d82fc 35
223e47cc 36pub fn main() {
1a4d82fc 37 let a = Struct { x: 1, y: 2 };
c34b1796 38 let b: Box<Trait> = Box::new(a);
1a4d82fc
JJ
39 b.f();
40 let c: &Trait = &a;
41 c.f();
42
c34b1796
AL
43 let out = io::stdout();
44 foo(Box::new(out));
223e47cc 45}