]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // ignore-test |
2 | ||
3 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT | |
4 | // file at the top-level directory of this distribution and at | |
5 | // http://rust-lang.org/COPYRIGHT. | |
6 | // | |
7 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
8 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
9 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
10 | // option. This file may not be copied, modified, or distributed | |
11 | // except according to those terms. | |
12 | ||
13 | // This is an interesting test case. We have a trait (Bar) that is | |
14 | // implemented for a `Box<Foo>` object (note: no bounds). And then we | |
15 | // have a `Box<Foo+Send>` object. The impl for `Box<Foo>` is applicable | |
16 | // to `Box<Foo+Send>` because: | |
17 | // | |
18 | // 1. The trait Bar is contravariant w/r/t Self because `Self` appears | |
19 | // only in argument position. | |
20 | // 2. The impl provides `Bar for Box<Foo>` | |
21 | // 3. The fn `wants_bar()` requires `Bar for Box<Foo:Send>`. | |
22 | // 4. `Bar for Box<Foo> <: Bar for Box<Foo:Send>` because | |
23 | // `Box<Foo:Send> <: Box<Foo>`. | |
24 | ||
25 | #![allow(unknown_features)] | |
26 | #![feature(box_syntax)] | |
27 | ||
28 | trait Foo { } | |
29 | struct SFoo; | |
30 | impl Foo for SFoo { } | |
31 | ||
32 | trait Bar { fn dummy(&self); } | |
33 | impl Bar for Box<Foo> { fn dummy(&self) { } } | |
34 | ||
35 | fn wants_bar<B:Bar>(b: &B) { } | |
36 | ||
37 | fn main() { | |
38 | let x: Box<Foo+Send> = (box SFoo); | |
39 | wants_bar(&x); | |
40 | } |