Skip to content

Commit d8fc73f

Browse files
committed
---
yaml --- r: 179790 b: refs/heads/tmp c: a1b3189 h: refs/heads/master v: v3
1 parent 8592bcf commit d8fc73f

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 44a287e6eb22ec3c2a687fc156813577464017f7
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: d9393c21d788347a993108021e8395d0ff992d03
37+
refs/heads/tmp: a1b3189f4864f1ada755e9ebc2e0ce1ac5bf2e06
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2015 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+
// Given `<expr> as Box<Trait>`, we should be able to infer that a
12+
// `Box<_>` is the expected type.
13+
14+
trait Foo { fn foo(&self) -> u32; }
15+
impl Foo for u32 { fn foo(&self) -> u32 { *self } }
16+
17+
// (another impl to ensure trait-matching cannot just choose from a singleton set)
18+
impl Foo for () { fn foo(&self) -> u32 { -176 } }
19+
20+
trait Boxed { fn make() -> Self; }
21+
impl Boxed for Box<u32> { fn make() -> Self { Box::new(7) } }
22+
23+
// (another impl to ensure trait-matching cannot just choose from a singleton set)
24+
impl Boxed for () { fn make() -> Self { () } }
25+
26+
fn boxed_foo() {
27+
let b7 = Boxed::make() as Box<Foo>;
28+
assert_eq!(b7.foo(), 7);
29+
}
30+
31+
trait Refed<'a,T> { fn make(&'a T) -> Self; }
32+
impl<'a> Refed<'a, u32> for &'a u32 { fn make(x: &'a u32) -> Self { x } }
33+
34+
// (another impl to ensure trait-matching cannot just choose from a singleton set)
35+
impl<'a,'b> Refed<'a, ()> for &'b () { fn make(_: &'a ()) -> Self { static U: () = (); &U } }
36+
37+
fn refed_foo() {
38+
let a = 8;
39+
let b7 = Refed::make(&a) as &Foo;
40+
assert_eq!(b7.foo(), 8);
41+
}
42+
43+
fn check_subtyping_works() {
44+
fn inner<'short, 'long:'short>(_s: &'short u32,
45+
l: &'long u32) -> &'short (Foo+'short) {
46+
Refed::make(l) as &Foo
47+
}
48+
49+
let a = 9;
50+
let b = 10;
51+
let r = inner(&b, &a);
52+
assert_eq!(r.foo(), 9);
53+
}
54+
55+
pub fn main() {
56+
boxed_foo();
57+
refed_foo();
58+
check_subtyping_works();
59+
}

0 commit comments

Comments
 (0)