add run-pass tests

This commit is contained in:
Michael Hewson 2017-11-09 11:42:41 -05:00
parent ddc21d567e
commit 77cd993fd1
4 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(arbitrary_self_types)]
struct Foo;
struct Bar;
impl std::ops::Deref for Bar {
type Target = Foo;
fn deref(&self) -> &Foo {
&Foo
}
}
impl Foo {
fn bar(self: Bar) -> i32 { 3 }
}
fn main() {
assert_eq!(3, Bar.bar());
}

View File

@ -0,0 +1,33 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(arbitrary_self_types)]
use std::rc::Rc;
struct Foo {
x: i32,
y: i32,
}
impl Foo {
fn x(self: &Rc<Self>) -> i32 {
self.x
}
fn y(self: Rc<Self>) -> i32 {
self.y
}
}
fn main() {
let foo = Rc::new(Foo {x: 3, y: 4});
assert_eq!(3, foo.x());
assert_eq!(4, foo.y());
}

View File

@ -0,0 +1,28 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(arbitrary_self_types)]
use std::rc::Rc;
trait Trait {
fn trait_method<'a>(self: &'a Box<Rc<Self>>) -> &'a [i32];
}
impl Trait for Vec<i32> {
fn trait_method<'a>(self: &'a Box<Rc<Self>>) -> &'a [i32] {
&***self
}
}
fn main() {
let v = vec![1,2,3];
assert_eq!(&[1,2,3], Box::new(Rc::new(v)).trait_method());
}

View File

@ -0,0 +1,25 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(arbitrary_self_types)]
use std::rc::Rc;
struct Foo<T: ?Sized>(T);
impl Foo<[u8]> {
fn len(self: Rc<Self>) -> usize {
self.0.len()
}
}
fn main() {
let rc = Rc::new(Foo([1u8,2,3])) as Rc<Foo<[u8]>>;
assert_eq!(3, rc.len());
}