File tree Expand file tree Collapse file tree 3 files changed +92
-1
lines changed
branches/beta/src/test/run-pass Expand file tree Collapse file tree 3 files changed +92
-1
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
29
29
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
30
30
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
31
31
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32
- refs/heads/beta: 03d4d5f80ed1d9e168869bdb244e4fef67b7d3d0
32
+ refs/heads/beta: db1b14a194cbdbba813aeb4773ee7fa203a40fb1
33
33
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
34
34
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35
35
refs/heads/tmp: 579e31929feff51dcaf8d444648eff8de735f91a
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments