Skip to content

Commit 0b36f9d

Browse files
committed
---
yaml --- r: 210699 b: refs/heads/try c: db1b14a h: refs/heads/master i: 210697: c9dde55 210695: cd4e8db v: v3
1 parent bf24a62 commit 0b36f9d

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: 03d4d5f80ed1d9e168869bdb244e4fef67b7d3d0
5+
refs/heads/try: db1b14a194cbdbba813aeb4773ee7fa203a40fb1
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
// Test a very simple custom DST coercion.
12+
13+
#![feature(core)]
14+
15+
use std::ops::CoerceUnsized;
16+
use std::marker::Unsize;
17+
18+
struct Bar<T: ?Sized> {
19+
x: *const T,
20+
}
21+
22+
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Bar<U>> for Bar<T> {}
23+
24+
trait Baz {
25+
fn get(&self) -> i32;
26+
}
27+
28+
impl Baz for i32 {
29+
fn get(&self) -> i32 {
30+
*self
31+
}
32+
}
33+
34+
fn main() {
35+
// Arrays.
36+
let a: Bar<[i32; 3]> = Bar { x: &[1, 2, 3] };
37+
// This is the actual coercion.
38+
let b: Bar<[i32]> = a;
39+
40+
unsafe {
41+
assert_eq!((*b.x)[0], 1);
42+
assert_eq!((*b.x)[1], 2);
43+
assert_eq!((*b.x)[2], 3);
44+
}
45+
46+
// Trait objects.
47+
let a: Bar<i32> = Bar { x: &42 };
48+
let b: Bar<Baz> = a;
49+
unsafe {
50+
assert_eq!((*b.x).get(), 42);
51+
}
52+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
// Test a very simple custom DST coercion.
12+
13+
#![feature(core)]
14+
15+
use std::rc::Rc;
16+
17+
trait Baz {
18+
fn get(&self) -> i32;
19+
}
20+
21+
impl Baz for i32 {
22+
fn get(&self) -> i32 {
23+
*self
24+
}
25+
}
26+
27+
fn main() {
28+
let a: Rc<[i32; 3]> = Rc::new([1, 2, 3]);
29+
let b: Rc<[i32]> = a;
30+
assert_eq!(b[0], 1);
31+
assert_eq!(b[1], 2);
32+
assert_eq!(b[2], 3);
33+
34+
let a: Rc<i32> = Rc::new(42);
35+
let b: Rc<Baz> = a.clone();
36+
assert_eq!(b.get(), 42);
37+
38+
let _c = b.clone();
39+
}

0 commit comments

Comments
 (0)