Skip to content

Commit

Permalink
add run-pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeyhew committed Nov 9, 2017
1 parent ddc21d5 commit 77cd993
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/run-pass/arbitrary_self_types_silly.rs
@@ -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());
}
33 changes: 33 additions & 0 deletions src/test/run-pass/arbitrary_self_types_struct.rs
@@ -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());
}
28 changes: 28 additions & 0 deletions src/test/run-pass/arbitrary_self_types_trait.rs
@@ -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());
}
25 changes: 25 additions & 0 deletions src/test/run-pass/arbitrary_self_types_unsized_struct.rs
@@ -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());
}

0 comments on commit 77cd993

Please sign in to comment.