From 3e73ca6e336650eb0cb8429b3932d63d71c2a476 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 19 May 2019 22:17:12 +0900 Subject: Move run-pass/self/* to ui/self --- .../self/auxiliary/explicit_self_xcrate.rs | 15 ----- .../run-pass/self/builtin-superkinds-self-type.rs | 20 ------ .../run-pass/self/by-value-self-in-mut-slot.rs | 22 ------- src/test/run-pass/self/explicit-self-closures.rs | 17 ----- src/test/run-pass/self/explicit-self-generic.rs | 29 --------- .../run-pass/self/explicit-self-objects-uniq.rs | 22 ------- src/test/run-pass/self/explicit-self.rs | 73 ---------------------- src/test/run-pass/self/explicit_self_xcrate_exe.rs | 12 ---- src/test/run-pass/self/move-self.rs | 19 ------ .../self/object-safety-sized-self-by-value-self.rs | 39 ------------ .../object-safety-sized-self-generic-method.rs | 39 ------------ .../self/object-safety-sized-self-return-Self.rs | 39 ------------ src/test/run-pass/self/self-impl.rs | 70 --------------------- .../self/self-in-mut-slot-default-method.rs | 36 ----------- .../self/self-in-mut-slot-immediate-value.rs | 23 ------- src/test/run-pass/self/self-in-typedefs.rs | 32 ---------- src/test/run-pass/self/self-re-assign.rs | 17 ----- src/test/run-pass/self/self-shadowing-import.rs | 16 ----- src/test/run-pass/self/self-type-param.rs | 19 ------ src/test/run-pass/self/string-self-append.rs | 14 ----- src/test/run-pass/self/ufcs-explicit-self.rs | 49 --------------- src/test/run-pass/self/uniq-self-in-mut-slot.rs | 23 ------- src/test/run-pass/self/where-for-self.rs | 51 --------------- src/test/ui/self/auxiliary/explicit_self_xcrate.rs | 15 +++++ src/test/ui/self/builtin-superkinds-self-type.rs | 20 ++++++ src/test/ui/self/by-value-self-in-mut-slot.rs | 22 +++++++ src/test/ui/self/explicit-self-closures.rs | 17 +++++ src/test/ui/self/explicit-self-generic.rs | 29 +++++++++ src/test/ui/self/explicit-self-objects-uniq.rs | 22 +++++++ src/test/ui/self/explicit-self.rs | 73 ++++++++++++++++++++++ src/test/ui/self/explicit_self_xcrate_exe.rs | 12 ++++ src/test/ui/self/move-self.rs | 19 ++++++ .../self/object-safety-sized-self-by-value-self.rs | 39 ++++++++++++ .../object-safety-sized-self-generic-method.rs | 39 ++++++++++++ .../self/object-safety-sized-self-return-Self.rs | 39 ++++++++++++ src/test/ui/self/self-impl-2.rs | 70 +++++++++++++++++++++ .../ui/self/self-in-mut-slot-default-method.rs | 36 +++++++++++ .../ui/self/self-in-mut-slot-immediate-value.rs | 23 +++++++ src/test/ui/self/self-in-typedefs.rs | 32 ++++++++++ src/test/ui/self/self-re-assign.rs | 17 +++++ src/test/ui/self/self-shadowing-import.rs | 16 +++++ src/test/ui/self/self-type-param.rs | 19 ++++++ src/test/ui/self/string-self-append.rs | 14 +++++ src/test/ui/self/ufcs-explicit-self.rs | 49 +++++++++++++++ src/test/ui/self/uniq-self-in-mut-slot.rs | 23 +++++++ src/test/ui/self/where-for-self.rs | 51 +++++++++++++++ 46 files changed, 696 insertions(+), 696 deletions(-) delete mode 100644 src/test/run-pass/self/auxiliary/explicit_self_xcrate.rs delete mode 100644 src/test/run-pass/self/builtin-superkinds-self-type.rs delete mode 100644 src/test/run-pass/self/by-value-self-in-mut-slot.rs delete mode 100644 src/test/run-pass/self/explicit-self-closures.rs delete mode 100644 src/test/run-pass/self/explicit-self-generic.rs delete mode 100644 src/test/run-pass/self/explicit-self-objects-uniq.rs delete mode 100644 src/test/run-pass/self/explicit-self.rs delete mode 100644 src/test/run-pass/self/explicit_self_xcrate_exe.rs delete mode 100644 src/test/run-pass/self/move-self.rs delete mode 100644 src/test/run-pass/self/object-safety-sized-self-by-value-self.rs delete mode 100644 src/test/run-pass/self/object-safety-sized-self-generic-method.rs delete mode 100644 src/test/run-pass/self/object-safety-sized-self-return-Self.rs delete mode 100644 src/test/run-pass/self/self-impl.rs delete mode 100644 src/test/run-pass/self/self-in-mut-slot-default-method.rs delete mode 100644 src/test/run-pass/self/self-in-mut-slot-immediate-value.rs delete mode 100644 src/test/run-pass/self/self-in-typedefs.rs delete mode 100644 src/test/run-pass/self/self-re-assign.rs delete mode 100644 src/test/run-pass/self/self-shadowing-import.rs delete mode 100644 src/test/run-pass/self/self-type-param.rs delete mode 100644 src/test/run-pass/self/string-self-append.rs delete mode 100644 src/test/run-pass/self/ufcs-explicit-self.rs delete mode 100644 src/test/run-pass/self/uniq-self-in-mut-slot.rs delete mode 100644 src/test/run-pass/self/where-for-self.rs create mode 100644 src/test/ui/self/auxiliary/explicit_self_xcrate.rs create mode 100644 src/test/ui/self/builtin-superkinds-self-type.rs create mode 100644 src/test/ui/self/by-value-self-in-mut-slot.rs create mode 100644 src/test/ui/self/explicit-self-closures.rs create mode 100644 src/test/ui/self/explicit-self-generic.rs create mode 100644 src/test/ui/self/explicit-self-objects-uniq.rs create mode 100644 src/test/ui/self/explicit-self.rs create mode 100644 src/test/ui/self/explicit_self_xcrate_exe.rs create mode 100644 src/test/ui/self/move-self.rs create mode 100644 src/test/ui/self/object-safety-sized-self-by-value-self.rs create mode 100644 src/test/ui/self/object-safety-sized-self-generic-method.rs create mode 100644 src/test/ui/self/object-safety-sized-self-return-Self.rs create mode 100644 src/test/ui/self/self-impl-2.rs create mode 100644 src/test/ui/self/self-in-mut-slot-default-method.rs create mode 100644 src/test/ui/self/self-in-mut-slot-immediate-value.rs create mode 100644 src/test/ui/self/self-in-typedefs.rs create mode 100644 src/test/ui/self/self-re-assign.rs create mode 100644 src/test/ui/self/self-shadowing-import.rs create mode 100644 src/test/ui/self/self-type-param.rs create mode 100644 src/test/ui/self/string-self-append.rs create mode 100644 src/test/ui/self/ufcs-explicit-self.rs create mode 100644 src/test/ui/self/uniq-self-in-mut-slot.rs create mode 100644 src/test/ui/self/where-for-self.rs diff --git a/src/test/run-pass/self/auxiliary/explicit_self_xcrate.rs b/src/test/run-pass/self/auxiliary/explicit_self_xcrate.rs deleted file mode 100644 index 25cdfa90990..00000000000 --- a/src/test/run-pass/self/auxiliary/explicit_self_xcrate.rs +++ /dev/null @@ -1,15 +0,0 @@ -pub trait Foo { - #[inline(always)] - fn f(&self); -} - -pub struct Bar { - pub x: String -} - -impl Foo for Bar { - #[inline(always)] - fn f(&self) { - println!("{}", (*self).x); - } -} diff --git a/src/test/run-pass/self/builtin-superkinds-self-type.rs b/src/test/run-pass/self/builtin-superkinds-self-type.rs deleted file mode 100644 index c56542bb468..00000000000 --- a/src/test/run-pass/self/builtin-superkinds-self-type.rs +++ /dev/null @@ -1,20 +0,0 @@ -// run-pass -// Tests the ability for the Self type in default methods to use -// capabilities granted by builtin kinds as supertraits. - - -use std::sync::mpsc::{Sender, channel}; - -trait Foo : Send + Sized + 'static { - fn foo(self, tx: Sender) { - tx.send(self).unwrap(); - } -} - -impl Foo for T { } - -pub fn main() { - let (tx, rx) = channel(); - 1193182.foo(tx); - assert_eq!(rx.recv().unwrap(), 1193182); -} diff --git a/src/test/run-pass/self/by-value-self-in-mut-slot.rs b/src/test/run-pass/self/by-value-self-in-mut-slot.rs deleted file mode 100644 index 267afd1dcad..00000000000 --- a/src/test/run-pass/self/by-value-self-in-mut-slot.rs +++ /dev/null @@ -1,22 +0,0 @@ -// run-pass - -struct X { - a: isize -} - -trait Changer { - fn change(self) -> Self; -} - -impl Changer for X { - fn change(mut self) -> X { - self.a = 55; - self - } -} - -pub fn main() { - let x = X { a: 32 }; - let new_x = x.change(); - assert_eq!(new_x.a, 55); -} diff --git a/src/test/run-pass/self/explicit-self-closures.rs b/src/test/run-pass/self/explicit-self-closures.rs deleted file mode 100644 index 61be98fe3d3..00000000000 --- a/src/test/run-pass/self/explicit-self-closures.rs +++ /dev/null @@ -1,17 +0,0 @@ -// run-pass -#![allow(dead_code)] -// Test to make sure that explicit self params work inside closures - -// pretty-expanded FIXME #23616 - -struct Box { - x: usize -} - -impl Box { - pub fn set_many(&mut self, xs: &[usize]) { - for x in xs { self.x = *x; } - } -} - -pub fn main() {} diff --git a/src/test/run-pass/self/explicit-self-generic.rs b/src/test/run-pass/self/explicit-self-generic.rs deleted file mode 100644 index 03f72a5513c..00000000000 --- a/src/test/run-pass/self/explicit-self-generic.rs +++ /dev/null @@ -1,29 +0,0 @@ -// run-pass -#![allow(dead_code)] -#![feature(box_syntax)] - -#[derive(Copy, Clone)] -struct LM { resize_at: usize, size: usize } - -enum HashMap { - HashMap_(LM, Vec<(K,V)>) -} - -fn linear_map() -> HashMap { - HashMap::HashMap_(LM{ - resize_at: 32, - size: 0}, Vec::new()) -} - -impl HashMap { - pub fn len(&mut self) -> usize { - match *self { - HashMap::HashMap_(ref l, _) => l.size - } - } -} - -pub fn main() { - let mut m: Box<_> = box linear_map::<(),()>(); - assert_eq!(m.len(), 0); -} diff --git a/src/test/run-pass/self/explicit-self-objects-uniq.rs b/src/test/run-pass/self/explicit-self-objects-uniq.rs deleted file mode 100644 index f95686cf112..00000000000 --- a/src/test/run-pass/self/explicit-self-objects-uniq.rs +++ /dev/null @@ -1,22 +0,0 @@ -// run-pass -#![feature(box_syntax)] - -trait Foo { - fn f(self: Box); -} - -struct S { - x: isize -} - -impl Foo for S { - fn f(self: Box) { - assert_eq!(self.x, 3); - } -} - -pub fn main() { - let x = box S { x: 3 }; - let y = x as Box; - y.f(); -} diff --git a/src/test/run-pass/self/explicit-self.rs b/src/test/run-pass/self/explicit-self.rs deleted file mode 100644 index 6d19d33b6fe..00000000000 --- a/src/test/run-pass/self/explicit-self.rs +++ /dev/null @@ -1,73 +0,0 @@ -// run-pass -#![allow(dead_code)] -#![allow(non_camel_case_types)] -#![allow(non_upper_case_globals)] - -#![feature(box_syntax)] - -static tau: f64 = 2.0*3.14159265358979323; - -struct Point {x: f64, y: f64} -struct Size {w: f64, h: f64} -enum shape { - circle(Point, f64), - rectangle(Point, Size) -} - - -fn compute_area(shape: &shape) -> f64 { - match *shape { - shape::circle(_, radius) => 0.5 * tau * radius * radius, - shape::rectangle(_, ref size) => size.w * size.h - } -} - -impl shape { - // self is in the implicit self region - pub fn select<'r, T>(&self, threshold: f64, a: &'r T, b: &'r T) - -> &'r T { - if compute_area(self) > threshold {a} else {b} - } -} - -fn select_based_on_unit_circle<'r, T>( - threshold: f64, a: &'r T, b: &'r T) -> &'r T { - - let shape = &shape::circle(Point{x: 0.0, y: 0.0}, 1.0); - shape.select(threshold, a, b) -} - -#[derive(Clone)] -struct thing { - x: A -} - -#[derive(Clone)] -struct A { - a: isize -} - -fn thing(x: A) -> thing { - thing { - x: x - } -} - -impl thing { - pub fn bar(self: Box) -> isize { self.x.a } - pub fn quux(&self) -> isize { self.x.a } - pub fn baz<'a>(&'a self) -> &'a A { &self.x } - pub fn spam(self) -> isize { self.x.a } -} - -trait Nus { fn f(&self); } -impl Nus for thing { fn f(&self) {} } - -pub fn main() { - let y: Box<_> = box thing(A {a: 10}); - assert_eq!(y.clone().bar(), 10); - assert_eq!(y.quux(), 10); - - let z = thing(A {a: 11}); - assert_eq!(z.spam(), 11); -} diff --git a/src/test/run-pass/self/explicit_self_xcrate_exe.rs b/src/test/run-pass/self/explicit_self_xcrate_exe.rs deleted file mode 100644 index c3796f73ab5..00000000000 --- a/src/test/run-pass/self/explicit_self_xcrate_exe.rs +++ /dev/null @@ -1,12 +0,0 @@ -// run-pass -// aux-build:explicit_self_xcrate.rs - -// pretty-expanded FIXME #23616 - -extern crate explicit_self_xcrate; -use explicit_self_xcrate::{Foo, Bar}; - -pub fn main() { - let x = Bar { x: "hello".to_string() }; - x.f(); -} diff --git a/src/test/run-pass/self/move-self.rs b/src/test/run-pass/self/move-self.rs deleted file mode 100644 index 66032780b81..00000000000 --- a/src/test/run-pass/self/move-self.rs +++ /dev/null @@ -1,19 +0,0 @@ -// run-pass -struct S { - x: String -} - -impl S { - pub fn foo(self) { - self.bar(); - } - - pub fn bar(self) { - println!("{}", self.x); - } -} - -pub fn main() { - let x = S { x: "Hello!".to_string() }; - x.foo(); -} diff --git a/src/test/run-pass/self/object-safety-sized-self-by-value-self.rs b/src/test/run-pass/self/object-safety-sized-self-by-value-self.rs deleted file mode 100644 index ae0512666ce..00000000000 --- a/src/test/run-pass/self/object-safety-sized-self-by-value-self.rs +++ /dev/null @@ -1,39 +0,0 @@ -// run-pass -#![allow(unused_mut)] -// Check that a trait is still object-safe (and usable) if it has -// methods with by-value self so long as they require `Self : Sized`. - - -trait Counter { - fn tick(&mut self) -> u32; - fn get(self) -> u32 where Self : Sized; -} - -struct CCounter { - c: u32 -} - -impl Counter for CCounter { - fn tick(&mut self) -> u32 { self.c += 1; self.c } - fn get(self) -> u32 where Self : Sized { self.c } -} - -fn tick1(mut c: C) -> u32 { - tick2(&mut c); - c.get() -} - -fn tick2(c: &mut Counter) { - tick3(c); -} - -fn tick3(c: &mut C) { - c.tick(); - c.tick(); -} - -fn main() { - let mut c = CCounter { c: 0 }; - let value = tick1(c); - assert_eq!(value, 2); -} diff --git a/src/test/run-pass/self/object-safety-sized-self-generic-method.rs b/src/test/run-pass/self/object-safety-sized-self-generic-method.rs deleted file mode 100644 index 0b3f6633737..00000000000 --- a/src/test/run-pass/self/object-safety-sized-self-generic-method.rs +++ /dev/null @@ -1,39 +0,0 @@ -// run-pass -#![allow(unused_variables)] -// Check that a trait is still object-safe (and usable) if it has -// generic methods so long as they require `Self : Sized`. - - -trait Counter { - fn tick(&mut self) -> u32; - fn with(&self, f: F) where Self : Sized; -} - -struct CCounter { - c: u32 -} - -impl Counter for CCounter { - fn tick(&mut self) -> u32 { self.c += 1; self.c } - fn with(&self, f: F) { f(self.c); } -} - -fn tick1(c: &mut C) { - tick2(c); - c.with(|i| ()); -} - -fn tick2(c: &mut Counter) { - tick3(c); -} - -fn tick3(c: &mut C) { - c.tick(); - c.tick(); -} - -fn main() { - let mut c = CCounter { c: 0 }; - tick1(&mut c); - assert_eq!(c.tick(), 3); -} diff --git a/src/test/run-pass/self/object-safety-sized-self-return-Self.rs b/src/test/run-pass/self/object-safety-sized-self-return-Self.rs deleted file mode 100644 index e88dba0a4e8..00000000000 --- a/src/test/run-pass/self/object-safety-sized-self-return-Self.rs +++ /dev/null @@ -1,39 +0,0 @@ -// run-pass -// Check that a trait is still object-safe (and usable) if it has -// methods that return `Self` so long as they require `Self : Sized`. - - -trait Counter { - fn new() -> Self where Self : Sized; - fn tick(&mut self) -> u32; -} - -struct CCounter { - c: u32 -} - -impl Counter for CCounter { - fn new() -> CCounter { CCounter { c: 0 } } - fn tick(&mut self) -> u32 { self.c += 1; self.c } -} - -fn preticked() -> C { - let mut c: C = Counter::new(); - tick(&mut c); - c -} - -fn tick(c: &mut Counter) { - tick_generic(c); -} - -fn tick_generic(c: &mut C) { - c.tick(); - c.tick(); -} - -fn main() { - let mut c = preticked::(); - tick(&mut c); - assert_eq!(c.tick(), 5); -} diff --git a/src/test/run-pass/self/self-impl.rs b/src/test/run-pass/self/self-impl.rs deleted file mode 100644 index 23d513e3fac..00000000000 --- a/src/test/run-pass/self/self-impl.rs +++ /dev/null @@ -1,70 +0,0 @@ -// run-pass -#![allow(dead_code)] -#![allow(unused_variables)] -// Test that we can use `Self` types in impls in the expected way. - -// pretty-expanded FIXME #23616 - -#![feature(box_syntax)] - -struct Foo; - -// Test uses on inherent impl. -impl Foo { - fn foo(_x: Self, _y: &Self, _z: Box) -> Self { - Foo - } - - fn baz() { - // Test that Self cannot be shadowed. - type Foo = i32; - // There is no empty method on i32. - Self::empty(); - - let _: Self = Foo; - } - - fn empty() {} -} - -// Test uses when implementing a trait and with a type parameter. -pub struct Baz { - pub f: X, -} - -trait SuperBar { - type SuperQux; -} - -trait Bar: SuperBar { - type Qux; - - fn bar(x: Self, y: &Self, z: Box, _: Self::SuperQux) -> Self; - fn dummy(&self, x: X) { } -} - -impl SuperBar for Box> { - type SuperQux = bool; -} - -impl Bar for Box> { - type Qux = i32; - - fn bar(_x: Self, _y: &Self, _z: Box, _: Self::SuperQux) -> Self { - let _: Self::Qux = 42; - let _: >::Qux = 42; - - let _: Self::SuperQux = true; - let _: ::SuperQux = true; - - box Baz { f: 42 } - } -} - -fn main() { - let _: Foo = Foo::foo(Foo, &Foo, box Foo); - let _: Box> = Bar::bar(box Baz { f: 42 }, - &box Baz { f: 42 }, - box box Baz { f: 42 }, - true); -} diff --git a/src/test/run-pass/self/self-in-mut-slot-default-method.rs b/src/test/run-pass/self/self-in-mut-slot-default-method.rs deleted file mode 100644 index 82c5f58f020..00000000000 --- a/src/test/run-pass/self/self-in-mut-slot-default-method.rs +++ /dev/null @@ -1,36 +0,0 @@ -// run-pass -#![feature(box_syntax)] - -struct X { - a: isize -} - -trait Changer : Sized { - fn change(mut self) -> Self { - self.set_to(55); - self - } - - fn change_again(mut self: Box) -> Box { - self.set_to(45); - self - } - - fn set_to(&mut self, a: isize); -} - -impl Changer for X { - fn set_to(&mut self, a: isize) { - self.a = a; - } -} - -pub fn main() { - let x = X { a: 32 }; - let new_x = x.change(); - assert_eq!(new_x.a, 55); - - let x: Box<_> = box new_x; - let new_x = x.change_again(); - assert_eq!(new_x.a, 45); -} diff --git a/src/test/run-pass/self/self-in-mut-slot-immediate-value.rs b/src/test/run-pass/self/self-in-mut-slot-immediate-value.rs deleted file mode 100644 index 60865304f1c..00000000000 --- a/src/test/run-pass/self/self-in-mut-slot-immediate-value.rs +++ /dev/null @@ -1,23 +0,0 @@ -// run-pass -// Assert that `mut self` on an immediate value doesn't -// allow mutating the original - issue #10615. - - -#[derive(Copy, Clone)] -struct Value { - n: isize -} - -impl Value { - fn squared(mut self) -> Value { - self.n *= self.n; - self - } -} - -pub fn main() { - let x = Value { n: 3 }; - let y = x.squared(); - assert_eq!(x.n, 3); - assert_eq!(y.n, 9); -} diff --git a/src/test/run-pass/self/self-in-typedefs.rs b/src/test/run-pass/self/self-in-typedefs.rs deleted file mode 100644 index 9c0906013fa..00000000000 --- a/src/test/run-pass/self/self-in-typedefs.rs +++ /dev/null @@ -1,32 +0,0 @@ -// run-pass - -#![feature(untagged_unions)] - -#![allow(dead_code)] -#![allow(unions_with_drop_fields)] - -enum A<'a, T: 'a> -where - Self: Send, T: PartialEq -{ - Foo(&'a Self), - Bar(T), -} - -struct B<'a, T: 'a> -where - Self: Send, T: PartialEq -{ - foo: &'a Self, - bar: T, -} - -union C<'a, T: 'a> -where - Self: Send, T: PartialEq -{ - foo: &'a Self, - bar: T, -} - -fn main() {} diff --git a/src/test/run-pass/self/self-re-assign.rs b/src/test/run-pass/self/self-re-assign.rs deleted file mode 100644 index a7b089ebff4..00000000000 --- a/src/test/run-pass/self/self-re-assign.rs +++ /dev/null @@ -1,17 +0,0 @@ -// run-pass -// Ensure assigning an owned or managed variable to itself works. In particular, -// that we do not glue_drop before we glue_take (#3290). - -#![feature(box_syntax)] - -use std::rc::Rc; - -pub fn main() { - let mut x: Box<_> = box 3; - x = x; - assert_eq!(*x, 3); - - let mut x = Rc::new(3); - x = x; - assert_eq!(*x, 3); -} diff --git a/src/test/run-pass/self/self-shadowing-import.rs b/src/test/run-pass/self/self-shadowing-import.rs deleted file mode 100644 index 1d60c6c2276..00000000000 --- a/src/test/run-pass/self/self-shadowing-import.rs +++ /dev/null @@ -1,16 +0,0 @@ -// run-pass - -mod a { - pub mod b { - pub mod a { - pub fn foo() -> isize { return 1; } - } - } -} - -mod c { - use a::b::a; - pub fn bar() { assert_eq!(a::foo(), 1); } -} - -pub fn main() { c::bar(); } diff --git a/src/test/run-pass/self/self-type-param.rs b/src/test/run-pass/self/self-type-param.rs deleted file mode 100644 index 6deae5f2d12..00000000000 --- a/src/test/run-pass/self/self-type-param.rs +++ /dev/null @@ -1,19 +0,0 @@ -// run-pass -#![allow(dead_code)] -// pretty-expanded FIXME #23616 - -trait MyTrait { - fn f(&self) -> Self; -} - -struct S { - x: isize -} - -impl MyTrait for S { - fn f(&self) -> S { - S { x: 3 } - } -} - -pub fn main() {} diff --git a/src/test/run-pass/self/string-self-append.rs b/src/test/run-pass/self/string-self-append.rs deleted file mode 100644 index e63dc0090cb..00000000000 --- a/src/test/run-pass/self/string-self-append.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-pass -pub fn main() { - // Make sure we properly handle repeated self-appends. - let mut a: String = "A".to_string(); - let mut i = 20; - let mut expected_len = 1; - while i > 0 { - println!("{}", a.len()); - assert_eq!(a.len(), expected_len); - a = format!("{}{}", a, a); - i -= 1; - expected_len *= 2; - } -} diff --git a/src/test/run-pass/self/ufcs-explicit-self.rs b/src/test/run-pass/self/ufcs-explicit-self.rs deleted file mode 100644 index 4e2405504f0..00000000000 --- a/src/test/run-pass/self/ufcs-explicit-self.rs +++ /dev/null @@ -1,49 +0,0 @@ -// run-pass -#![feature(box_syntax)] - -#[derive(Copy, Clone)] -struct Foo { - f: isize, -} - -impl Foo { - fn foo(self: Foo, x: isize) -> isize { - self.f + x - } - fn bar(self: &Foo, x: isize) -> isize { - self.f + x - } - fn baz(self: Box, x: isize) -> isize { - self.f + x - } -} - -#[derive(Copy, Clone)] -struct Bar { - f: T, -} - -impl Bar { - fn foo(self: Bar, x: isize) -> isize { - x - } - fn bar<'a>(self: &'a Bar, x: isize) -> isize { - x - } - fn baz(self: Bar, x: isize) -> isize { - x - } -} - -fn main() { - let foo: Box<_> = box Foo { - f: 1, - }; - println!("{} {} {}", foo.foo(2), foo.bar(2), foo.baz(2)); - let bar: Box<_> = box Bar { - f: 1, - }; - println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2)); - let bar: Box> = bar; - println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2)); -} diff --git a/src/test/run-pass/self/uniq-self-in-mut-slot.rs b/src/test/run-pass/self/uniq-self-in-mut-slot.rs deleted file mode 100644 index 695f06ecdda..00000000000 --- a/src/test/run-pass/self/uniq-self-in-mut-slot.rs +++ /dev/null @@ -1,23 +0,0 @@ -// run-pass -#![feature(box_syntax)] - -struct X { - a: isize -} - -trait Changer { - fn change(self: Box) -> Box; -} - -impl Changer for X { - fn change(mut self: Box) -> Box { - self.a = 55; - self - } -} - -pub fn main() { - let x: Box<_> = box X { a: 32 }; - let new_x = x.change(); - assert_eq!(new_x.a, 55); -} diff --git a/src/test/run-pass/self/where-for-self.rs b/src/test/run-pass/self/where-for-self.rs deleted file mode 100644 index 76c592dc49b..00000000000 --- a/src/test/run-pass/self/where-for-self.rs +++ /dev/null @@ -1,51 +0,0 @@ -// run-pass -// Test that we can quantify lifetimes outside a constraint (i.e., including -// the self type) in a where clause. - - -static mut COUNT: u32 = 1; - -trait Bar<'a> { - fn bar(&self); -} - -trait Baz<'a> -{ - fn baz(&self); -} - -impl<'a, 'b> Bar<'b> for &'a u32 { - fn bar(&self) { - unsafe { COUNT *= 2; } - } -} - -impl<'a, 'b> Baz<'b> for &'a u32 { - fn baz(&self) { - unsafe { COUNT *= 3; } - } -} - -// Test we can use the syntax for HRL including the self type. -fn foo1(x: &T) - where for<'a, 'b> &'a T: Bar<'b> -{ - x.bar() -} - -// Test we can quantify multiple bounds (i.e., the precedence is sensible). -fn foo2(x: &T) - where for<'a, 'b> &'a T: Bar<'b> + Baz<'b> -{ - x.baz(); - x.bar() -} - -fn main() { - let x = 42; - foo1(&x); - foo2(&x); - unsafe { - assert_eq!(COUNT, 12); - } -} diff --git a/src/test/ui/self/auxiliary/explicit_self_xcrate.rs b/src/test/ui/self/auxiliary/explicit_self_xcrate.rs new file mode 100644 index 00000000000..25cdfa90990 --- /dev/null +++ b/src/test/ui/self/auxiliary/explicit_self_xcrate.rs @@ -0,0 +1,15 @@ +pub trait Foo { + #[inline(always)] + fn f(&self); +} + +pub struct Bar { + pub x: String +} + +impl Foo for Bar { + #[inline(always)] + fn f(&self) { + println!("{}", (*self).x); + } +} diff --git a/src/test/ui/self/builtin-superkinds-self-type.rs b/src/test/ui/self/builtin-superkinds-self-type.rs new file mode 100644 index 00000000000..c56542bb468 --- /dev/null +++ b/src/test/ui/self/builtin-superkinds-self-type.rs @@ -0,0 +1,20 @@ +// run-pass +// Tests the ability for the Self type in default methods to use +// capabilities granted by builtin kinds as supertraits. + + +use std::sync::mpsc::{Sender, channel}; + +trait Foo : Send + Sized + 'static { + fn foo(self, tx: Sender) { + tx.send(self).unwrap(); + } +} + +impl Foo for T { } + +pub fn main() { + let (tx, rx) = channel(); + 1193182.foo(tx); + assert_eq!(rx.recv().unwrap(), 1193182); +} diff --git a/src/test/ui/self/by-value-self-in-mut-slot.rs b/src/test/ui/self/by-value-self-in-mut-slot.rs new file mode 100644 index 00000000000..267afd1dcad --- /dev/null +++ b/src/test/ui/self/by-value-self-in-mut-slot.rs @@ -0,0 +1,22 @@ +// run-pass + +struct X { + a: isize +} + +trait Changer { + fn change(self) -> Self; +} + +impl Changer for X { + fn change(mut self) -> X { + self.a = 55; + self + } +} + +pub fn main() { + let x = X { a: 32 }; + let new_x = x.change(); + assert_eq!(new_x.a, 55); +} diff --git a/src/test/ui/self/explicit-self-closures.rs b/src/test/ui/self/explicit-self-closures.rs new file mode 100644 index 00000000000..1217823da11 --- /dev/null +++ b/src/test/ui/self/explicit-self-closures.rs @@ -0,0 +1,17 @@ +// compile-pass +#![allow(dead_code)] +// Test to make sure that explicit self params work inside closures + +// pretty-expanded FIXME #23616 + +struct Box { + x: usize +} + +impl Box { + pub fn set_many(&mut self, xs: &[usize]) { + for x in xs { self.x = *x; } + } +} + +pub fn main() {} diff --git a/src/test/ui/self/explicit-self-generic.rs b/src/test/ui/self/explicit-self-generic.rs new file mode 100644 index 00000000000..03f72a5513c --- /dev/null +++ b/src/test/ui/self/explicit-self-generic.rs @@ -0,0 +1,29 @@ +// run-pass +#![allow(dead_code)] +#![feature(box_syntax)] + +#[derive(Copy, Clone)] +struct LM { resize_at: usize, size: usize } + +enum HashMap { + HashMap_(LM, Vec<(K,V)>) +} + +fn linear_map() -> HashMap { + HashMap::HashMap_(LM{ + resize_at: 32, + size: 0}, Vec::new()) +} + +impl HashMap { + pub fn len(&mut self) -> usize { + match *self { + HashMap::HashMap_(ref l, _) => l.size + } + } +} + +pub fn main() { + let mut m: Box<_> = box linear_map::<(),()>(); + assert_eq!(m.len(), 0); +} diff --git a/src/test/ui/self/explicit-self-objects-uniq.rs b/src/test/ui/self/explicit-self-objects-uniq.rs new file mode 100644 index 00000000000..f95686cf112 --- /dev/null +++ b/src/test/ui/self/explicit-self-objects-uniq.rs @@ -0,0 +1,22 @@ +// run-pass +#![feature(box_syntax)] + +trait Foo { + fn f(self: Box); +} + +struct S { + x: isize +} + +impl Foo for S { + fn f(self: Box) { + assert_eq!(self.x, 3); + } +} + +pub fn main() { + let x = box S { x: 3 }; + let y = x as Box; + y.f(); +} diff --git a/src/test/ui/self/explicit-self.rs b/src/test/ui/self/explicit-self.rs new file mode 100644 index 00000000000..6d19d33b6fe --- /dev/null +++ b/src/test/ui/self/explicit-self.rs @@ -0,0 +1,73 @@ +// run-pass +#![allow(dead_code)] +#![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] + +#![feature(box_syntax)] + +static tau: f64 = 2.0*3.14159265358979323; + +struct Point {x: f64, y: f64} +struct Size {w: f64, h: f64} +enum shape { + circle(Point, f64), + rectangle(Point, Size) +} + + +fn compute_area(shape: &shape) -> f64 { + match *shape { + shape::circle(_, radius) => 0.5 * tau * radius * radius, + shape::rectangle(_, ref size) => size.w * size.h + } +} + +impl shape { + // self is in the implicit self region + pub fn select<'r, T>(&self, threshold: f64, a: &'r T, b: &'r T) + -> &'r T { + if compute_area(self) > threshold {a} else {b} + } +} + +fn select_based_on_unit_circle<'r, T>( + threshold: f64, a: &'r T, b: &'r T) -> &'r T { + + let shape = &shape::circle(Point{x: 0.0, y: 0.0}, 1.0); + shape.select(threshold, a, b) +} + +#[derive(Clone)] +struct thing { + x: A +} + +#[derive(Clone)] +struct A { + a: isize +} + +fn thing(x: A) -> thing { + thing { + x: x + } +} + +impl thing { + pub fn bar(self: Box) -> isize { self.x.a } + pub fn quux(&self) -> isize { self.x.a } + pub fn baz<'a>(&'a self) -> &'a A { &self.x } + pub fn spam(self) -> isize { self.x.a } +} + +trait Nus { fn f(&self); } +impl Nus for thing { fn f(&self) {} } + +pub fn main() { + let y: Box<_> = box thing(A {a: 10}); + assert_eq!(y.clone().bar(), 10); + assert_eq!(y.quux(), 10); + + let z = thing(A {a: 11}); + assert_eq!(z.spam(), 11); +} diff --git a/src/test/ui/self/explicit_self_xcrate_exe.rs b/src/test/ui/self/explicit_self_xcrate_exe.rs new file mode 100644 index 00000000000..c3796f73ab5 --- /dev/null +++ b/src/test/ui/self/explicit_self_xcrate_exe.rs @@ -0,0 +1,12 @@ +// run-pass +// aux-build:explicit_self_xcrate.rs + +// pretty-expanded FIXME #23616 + +extern crate explicit_self_xcrate; +use explicit_self_xcrate::{Foo, Bar}; + +pub fn main() { + let x = Bar { x: "hello".to_string() }; + x.f(); +} diff --git a/src/test/ui/self/move-self.rs b/src/test/ui/self/move-self.rs new file mode 100644 index 00000000000..66032780b81 --- /dev/null +++ b/src/test/ui/self/move-self.rs @@ -0,0 +1,19 @@ +// run-pass +struct S { + x: String +} + +impl S { + pub fn foo(self) { + self.bar(); + } + + pub fn bar(self) { + println!("{}", self.x); + } +} + +pub fn main() { + let x = S { x: "Hello!".to_string() }; + x.foo(); +} diff --git a/src/test/ui/self/object-safety-sized-self-by-value-self.rs b/src/test/ui/self/object-safety-sized-self-by-value-self.rs new file mode 100644 index 00000000000..ae0512666ce --- /dev/null +++ b/src/test/ui/self/object-safety-sized-self-by-value-self.rs @@ -0,0 +1,39 @@ +// run-pass +#![allow(unused_mut)] +// Check that a trait is still object-safe (and usable) if it has +// methods with by-value self so long as they require `Self : Sized`. + + +trait Counter { + fn tick(&mut self) -> u32; + fn get(self) -> u32 where Self : Sized; +} + +struct CCounter { + c: u32 +} + +impl Counter for CCounter { + fn tick(&mut self) -> u32 { self.c += 1; self.c } + fn get(self) -> u32 where Self : Sized { self.c } +} + +fn tick1(mut c: C) -> u32 { + tick2(&mut c); + c.get() +} + +fn tick2(c: &mut Counter) { + tick3(c); +} + +fn tick3(c: &mut C) { + c.tick(); + c.tick(); +} + +fn main() { + let mut c = CCounter { c: 0 }; + let value = tick1(c); + assert_eq!(value, 2); +} diff --git a/src/test/ui/self/object-safety-sized-self-generic-method.rs b/src/test/ui/self/object-safety-sized-self-generic-method.rs new file mode 100644 index 00000000000..0b3f6633737 --- /dev/null +++ b/src/test/ui/self/object-safety-sized-self-generic-method.rs @@ -0,0 +1,39 @@ +// run-pass +#![allow(unused_variables)] +// Check that a trait is still object-safe (and usable) if it has +// generic methods so long as they require `Self : Sized`. + + +trait Counter { + fn tick(&mut self) -> u32; + fn with(&self, f: F) where Self : Sized; +} + +struct CCounter { + c: u32 +} + +impl Counter for CCounter { + fn tick(&mut self) -> u32 { self.c += 1; self.c } + fn with(&self, f: F) { f(self.c); } +} + +fn tick1(c: &mut C) { + tick2(c); + c.with(|i| ()); +} + +fn tick2(c: &mut Counter) { + tick3(c); +} + +fn tick3(c: &mut C) { + c.tick(); + c.tick(); +} + +fn main() { + let mut c = CCounter { c: 0 }; + tick1(&mut c); + assert_eq!(c.tick(), 3); +} diff --git a/src/test/ui/self/object-safety-sized-self-return-Self.rs b/src/test/ui/self/object-safety-sized-self-return-Self.rs new file mode 100644 index 00000000000..e88dba0a4e8 --- /dev/null +++ b/src/test/ui/self/object-safety-sized-self-return-Self.rs @@ -0,0 +1,39 @@ +// run-pass +// Check that a trait is still object-safe (and usable) if it has +// methods that return `Self` so long as they require `Self : Sized`. + + +trait Counter { + fn new() -> Self where Self : Sized; + fn tick(&mut self) -> u32; +} + +struct CCounter { + c: u32 +} + +impl Counter for CCounter { + fn new() -> CCounter { CCounter { c: 0 } } + fn tick(&mut self) -> u32 { self.c += 1; self.c } +} + +fn preticked() -> C { + let mut c: C = Counter::new(); + tick(&mut c); + c +} + +fn tick(c: &mut Counter) { + tick_generic(c); +} + +fn tick_generic(c: &mut C) { + c.tick(); + c.tick(); +} + +fn main() { + let mut c = preticked::(); + tick(&mut c); + assert_eq!(c.tick(), 5); +} diff --git a/src/test/ui/self/self-impl-2.rs b/src/test/ui/self/self-impl-2.rs new file mode 100644 index 00000000000..23d513e3fac --- /dev/null +++ b/src/test/ui/self/self-impl-2.rs @@ -0,0 +1,70 @@ +// run-pass +#![allow(dead_code)] +#![allow(unused_variables)] +// Test that we can use `Self` types in impls in the expected way. + +// pretty-expanded FIXME #23616 + +#![feature(box_syntax)] + +struct Foo; + +// Test uses on inherent impl. +impl Foo { + fn foo(_x: Self, _y: &Self, _z: Box) -> Self { + Foo + } + + fn baz() { + // Test that Self cannot be shadowed. + type Foo = i32; + // There is no empty method on i32. + Self::empty(); + + let _: Self = Foo; + } + + fn empty() {} +} + +// Test uses when implementing a trait and with a type parameter. +pub struct Baz { + pub f: X, +} + +trait SuperBar { + type SuperQux; +} + +trait Bar: SuperBar { + type Qux; + + fn bar(x: Self, y: &Self, z: Box, _: Self::SuperQux) -> Self; + fn dummy(&self, x: X) { } +} + +impl SuperBar for Box> { + type SuperQux = bool; +} + +impl Bar for Box> { + type Qux = i32; + + fn bar(_x: Self, _y: &Self, _z: Box, _: Self::SuperQux) -> Self { + let _: Self::Qux = 42; + let _: >::Qux = 42; + + let _: Self::SuperQux = true; + let _: ::SuperQux = true; + + box Baz { f: 42 } + } +} + +fn main() { + let _: Foo = Foo::foo(Foo, &Foo, box Foo); + let _: Box> = Bar::bar(box Baz { f: 42 }, + &box Baz { f: 42 }, + box box Baz { f: 42 }, + true); +} diff --git a/src/test/ui/self/self-in-mut-slot-default-method.rs b/src/test/ui/self/self-in-mut-slot-default-method.rs new file mode 100644 index 00000000000..82c5f58f020 --- /dev/null +++ b/src/test/ui/self/self-in-mut-slot-default-method.rs @@ -0,0 +1,36 @@ +// run-pass +#![feature(box_syntax)] + +struct X { + a: isize +} + +trait Changer : Sized { + fn change(mut self) -> Self { + self.set_to(55); + self + } + + fn change_again(mut self: Box) -> Box { + self.set_to(45); + self + } + + fn set_to(&mut self, a: isize); +} + +impl Changer for X { + fn set_to(&mut self, a: isize) { + self.a = a; + } +} + +pub fn main() { + let x = X { a: 32 }; + let new_x = x.change(); + assert_eq!(new_x.a, 55); + + let x: Box<_> = box new_x; + let new_x = x.change_again(); + assert_eq!(new_x.a, 45); +} diff --git a/src/test/ui/self/self-in-mut-slot-immediate-value.rs b/src/test/ui/self/self-in-mut-slot-immediate-value.rs new file mode 100644 index 00000000000..60865304f1c --- /dev/null +++ b/src/test/ui/self/self-in-mut-slot-immediate-value.rs @@ -0,0 +1,23 @@ +// run-pass +// Assert that `mut self` on an immediate value doesn't +// allow mutating the original - issue #10615. + + +#[derive(Copy, Clone)] +struct Value { + n: isize +} + +impl Value { + fn squared(mut self) -> Value { + self.n *= self.n; + self + } +} + +pub fn main() { + let x = Value { n: 3 }; + let y = x.squared(); + assert_eq!(x.n, 3); + assert_eq!(y.n, 9); +} diff --git a/src/test/ui/self/self-in-typedefs.rs b/src/test/ui/self/self-in-typedefs.rs new file mode 100644 index 00000000000..e4fe7324ef3 --- /dev/null +++ b/src/test/ui/self/self-in-typedefs.rs @@ -0,0 +1,32 @@ +// compile-pass + +#![feature(untagged_unions)] + +#![allow(dead_code)] +#![allow(unions_with_drop_fields)] + +enum A<'a, T: 'a> +where + Self: Send, T: PartialEq +{ + Foo(&'a Self), + Bar(T), +} + +struct B<'a, T: 'a> +where + Self: Send, T: PartialEq +{ + foo: &'a Self, + bar: T, +} + +union C<'a, T: 'a> +where + Self: Send, T: PartialEq +{ + foo: &'a Self, + bar: T, +} + +fn main() {} diff --git a/src/test/ui/self/self-re-assign.rs b/src/test/ui/self/self-re-assign.rs new file mode 100644 index 00000000000..a7b089ebff4 --- /dev/null +++ b/src/test/ui/self/self-re-assign.rs @@ -0,0 +1,17 @@ +// run-pass +// Ensure assigning an owned or managed variable to itself works. In particular, +// that we do not glue_drop before we glue_take (#3290). + +#![feature(box_syntax)] + +use std::rc::Rc; + +pub fn main() { + let mut x: Box<_> = box 3; + x = x; + assert_eq!(*x, 3); + + let mut x = Rc::new(3); + x = x; + assert_eq!(*x, 3); +} diff --git a/src/test/ui/self/self-shadowing-import.rs b/src/test/ui/self/self-shadowing-import.rs new file mode 100644 index 00000000000..1d60c6c2276 --- /dev/null +++ b/src/test/ui/self/self-shadowing-import.rs @@ -0,0 +1,16 @@ +// run-pass + +mod a { + pub mod b { + pub mod a { + pub fn foo() -> isize { return 1; } + } + } +} + +mod c { + use a::b::a; + pub fn bar() { assert_eq!(a::foo(), 1); } +} + +pub fn main() { c::bar(); } diff --git a/src/test/ui/self/self-type-param.rs b/src/test/ui/self/self-type-param.rs new file mode 100644 index 00000000000..57e01caa692 --- /dev/null +++ b/src/test/ui/self/self-type-param.rs @@ -0,0 +1,19 @@ +// compile-pass +#![allow(dead_code)] +// pretty-expanded FIXME #23616 + +trait MyTrait { + fn f(&self) -> Self; +} + +struct S { + x: isize +} + +impl MyTrait for S { + fn f(&self) -> S { + S { x: 3 } + } +} + +pub fn main() {} diff --git a/src/test/ui/self/string-self-append.rs b/src/test/ui/self/string-self-append.rs new file mode 100644 index 00000000000..e63dc0090cb --- /dev/null +++ b/src/test/ui/self/string-self-append.rs @@ -0,0 +1,14 @@ +// run-pass +pub fn main() { + // Make sure we properly handle repeated self-appends. + let mut a: String = "A".to_string(); + let mut i = 20; + let mut expected_len = 1; + while i > 0 { + println!("{}", a.len()); + assert_eq!(a.len(), expected_len); + a = format!("{}{}", a, a); + i -= 1; + expected_len *= 2; + } +} diff --git a/src/test/ui/self/ufcs-explicit-self.rs b/src/test/ui/self/ufcs-explicit-self.rs new file mode 100644 index 00000000000..4e2405504f0 --- /dev/null +++ b/src/test/ui/self/ufcs-explicit-self.rs @@ -0,0 +1,49 @@ +// run-pass +#![feature(box_syntax)] + +#[derive(Copy, Clone)] +struct Foo { + f: isize, +} + +impl Foo { + fn foo(self: Foo, x: isize) -> isize { + self.f + x + } + fn bar(self: &Foo, x: isize) -> isize { + self.f + x + } + fn baz(self: Box, x: isize) -> isize { + self.f + x + } +} + +#[derive(Copy, Clone)] +struct Bar { + f: T, +} + +impl Bar { + fn foo(self: Bar, x: isize) -> isize { + x + } + fn bar<'a>(self: &'a Bar, x: isize) -> isize { + x + } + fn baz(self: Bar, x: isize) -> isize { + x + } +} + +fn main() { + let foo: Box<_> = box Foo { + f: 1, + }; + println!("{} {} {}", foo.foo(2), foo.bar(2), foo.baz(2)); + let bar: Box<_> = box Bar { + f: 1, + }; + println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2)); + let bar: Box> = bar; + println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2)); +} diff --git a/src/test/ui/self/uniq-self-in-mut-slot.rs b/src/test/ui/self/uniq-self-in-mut-slot.rs new file mode 100644 index 00000000000..695f06ecdda --- /dev/null +++ b/src/test/ui/self/uniq-self-in-mut-slot.rs @@ -0,0 +1,23 @@ +// run-pass +#![feature(box_syntax)] + +struct X { + a: isize +} + +trait Changer { + fn change(self: Box) -> Box; +} + +impl Changer for X { + fn change(mut self: Box) -> Box { + self.a = 55; + self + } +} + +pub fn main() { + let x: Box<_> = box X { a: 32 }; + let new_x = x.change(); + assert_eq!(new_x.a, 55); +} diff --git a/src/test/ui/self/where-for-self.rs b/src/test/ui/self/where-for-self.rs new file mode 100644 index 00000000000..76c592dc49b --- /dev/null +++ b/src/test/ui/self/where-for-self.rs @@ -0,0 +1,51 @@ +// run-pass +// Test that we can quantify lifetimes outside a constraint (i.e., including +// the self type) in a where clause. + + +static mut COUNT: u32 = 1; + +trait Bar<'a> { + fn bar(&self); +} + +trait Baz<'a> +{ + fn baz(&self); +} + +impl<'a, 'b> Bar<'b> for &'a u32 { + fn bar(&self) { + unsafe { COUNT *= 2; } + } +} + +impl<'a, 'b> Baz<'b> for &'a u32 { + fn baz(&self) { + unsafe { COUNT *= 3; } + } +} + +// Test we can use the syntax for HRL including the self type. +fn foo1(x: &T) + where for<'a, 'b> &'a T: Bar<'b> +{ + x.bar() +} + +// Test we can quantify multiple bounds (i.e., the precedence is sensible). +fn foo2(x: &T) + where for<'a, 'b> &'a T: Bar<'b> + Baz<'b> +{ + x.baz(); + x.bar() +} + +fn main() { + let x = 42; + foo1(&x); + foo2(&x); + unsafe { + assert_eq!(COUNT, 12); + } +} -- cgit 1.4.1-3-g733a5