diff options
| author | Michael Hewson <michael@michaelhewson.ca> | 2017-11-09 11:42:41 -0500 |
|---|---|---|
| committer | Michael Hewson <michael@michaelhewson.ca> | 2017-11-09 11:42:41 -0500 |
| commit | 77cd993fd1582680cc01ce86d07e52b2e4b34fec (patch) | |
| tree | d4ea5b9e73da9b82ee5c4f02805e2eff350322bb | |
| parent | ddc21d567e50437d70f7f56377834135a2d34e6e (diff) | |
add run-pass tests
| -rw-r--r-- | src/test/run-pass/arbitrary_self_types_silly.rs | 29 | ||||
| -rw-r--r-- | src/test/run-pass/arbitrary_self_types_struct.rs | 33 | ||||
| -rw-r--r-- | src/test/run-pass/arbitrary_self_types_trait.rs | 28 | ||||
| -rw-r--r-- | src/test/run-pass/arbitrary_self_types_unsized_struct.rs | 25 |
4 files changed, 115 insertions, 0 deletions
diff --git a/src/test/run-pass/arbitrary_self_types_silly.rs b/src/test/run-pass/arbitrary_self_types_silly.rs new file mode 100644 index 00000000000..755a8d7ea29 --- /dev/null +++ b/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()); +} diff --git a/src/test/run-pass/arbitrary_self_types_struct.rs b/src/test/run-pass/arbitrary_self_types_struct.rs new file mode 100644 index 00000000000..961717de046 --- /dev/null +++ b/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()); +} diff --git a/src/test/run-pass/arbitrary_self_types_trait.rs b/src/test/run-pass/arbitrary_self_types_trait.rs new file mode 100644 index 00000000000..e74d614dd6b --- /dev/null +++ b/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()); +} diff --git a/src/test/run-pass/arbitrary_self_types_unsized_struct.rs b/src/test/run-pass/arbitrary_self_types_unsized_struct.rs new file mode 100644 index 00000000000..8dc40e7aab1 --- /dev/null +++ b/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()); +} |
