Skip to content

Commit 77cd993

Browse files
committed
add run-pass tests
1 parent ddc21d5 commit 77cd993

4 files changed

+115
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2017 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+
#![feature(arbitrary_self_types)]
11+
12+
struct Foo;
13+
struct Bar;
14+
15+
impl std::ops::Deref for Bar {
16+
type Target = Foo;
17+
18+
fn deref(&self) -> &Foo {
19+
&Foo
20+
}
21+
}
22+
23+
impl Foo {
24+
fn bar(self: Bar) -> i32 { 3 }
25+
}
26+
27+
fn main() {
28+
assert_eq!(3, Bar.bar());
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2017 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+
#![feature(arbitrary_self_types)]
11+
12+
use std::rc::Rc;
13+
14+
struct Foo {
15+
x: i32,
16+
y: i32,
17+
}
18+
19+
impl Foo {
20+
fn x(self: &Rc<Self>) -> i32 {
21+
self.x
22+
}
23+
24+
fn y(self: Rc<Self>) -> i32 {
25+
self.y
26+
}
27+
}
28+
29+
fn main() {
30+
let foo = Rc::new(Foo {x: 3, y: 4});
31+
assert_eq!(3, foo.x());
32+
assert_eq!(4, foo.y());
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 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+
#![feature(arbitrary_self_types)]
11+
12+
use std::rc::Rc;
13+
14+
trait Trait {
15+
fn trait_method<'a>(self: &'a Box<Rc<Self>>) -> &'a [i32];
16+
}
17+
18+
impl Trait for Vec<i32> {
19+
fn trait_method<'a>(self: &'a Box<Rc<Self>>) -> &'a [i32] {
20+
&***self
21+
}
22+
}
23+
24+
fn main() {
25+
let v = vec![1,2,3];
26+
27+
assert_eq!(&[1,2,3], Box::new(Rc::new(v)).trait_method());
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 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+
#![feature(arbitrary_self_types)]
11+
12+
use std::rc::Rc;
13+
14+
struct Foo<T: ?Sized>(T);
15+
16+
impl Foo<[u8]> {
17+
fn len(self: Rc<Self>) -> usize {
18+
self.0.len()
19+
}
20+
}
21+
22+
fn main() {
23+
let rc = Rc::new(Foo([1u8,2,3])) as Rc<Foo<[u8]>>;
24+
assert_eq!(3, rc.len());
25+
}

0 commit comments

Comments
 (0)