about summary refs log tree commit diff
path: root/src/test/ui/statics
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-27 01:33:01 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-27 18:56:16 +0300
commit9be35f82c1abf2ecbab489bca9eca138ea648312 (patch)
tree69888506e34af447d9748c0d542de3ba1dd76210 /src/test/ui/statics
parentca9faa52f5ada0054b1fa27d97aedf448afb059b (diff)
downloadrust-9be35f82c1abf2ecbab489bca9eca138ea648312.tar.gz
rust-9be35f82c1abf2ecbab489bca9eca138ea648312.zip
tests: Move run-pass tests without naming conflicts to ui
Diffstat (limited to 'src/test/ui/statics')
-rw-r--r--src/test/ui/statics/auxiliary/static-function-pointer-aux.rs4
-rw-r--r--src/test/ui/statics/auxiliary/static-methods-crate.rs29
-rw-r--r--src/test/ui/statics/auxiliary/static_fn_inline_xc_aux.rs12
-rw-r--r--src/test/ui/statics/auxiliary/static_fn_trait_xc_aux.rs11
-rw-r--r--src/test/ui/statics/auxiliary/static_mut_xc.rs1
-rw-r--r--src/test/ui/statics/static-fn-inline-xc.rs12
-rw-r--r--src/test/ui/statics/static-fn-trait-xc.rs12
-rw-r--r--src/test/ui/statics/static-function-pointer-xc.rs17
-rw-r--r--src/test/ui/statics/static-function-pointer.rs16
-rw-r--r--src/test/ui/statics/static-impl.rs66
-rw-r--r--src/test/ui/statics/static-method-in-trait-with-tps-intracrate.rs28
-rw-r--r--src/test/ui/statics/static-method-xcrate.rs13
-rw-r--r--src/test/ui/statics/static-methods-in-traits.rs26
-rw-r--r--src/test/ui/statics/static-methods-in-traits2.rs22
-rw-r--r--src/test/ui/statics/static-mut-foreign.rs41
-rw-r--r--src/test/ui/statics/static-mut-xc.rs39
-rw-r--r--src/test/ui/statics/static-recursive.rs36
17 files changed, 385 insertions, 0 deletions
diff --git a/src/test/ui/statics/auxiliary/static-function-pointer-aux.rs b/src/test/ui/statics/auxiliary/static-function-pointer-aux.rs
new file mode 100644
index 00000000000..4dfc25764a4
--- /dev/null
+++ b/src/test/ui/statics/auxiliary/static-function-pointer-aux.rs
@@ -0,0 +1,4 @@
+pub fn f(x: isize) -> isize { -x }
+
+pub static F: fn(isize) -> isize = f;
+pub static mut MutF: fn(isize) -> isize = f;
diff --git a/src/test/ui/statics/auxiliary/static-methods-crate.rs b/src/test/ui/statics/auxiliary/static-methods-crate.rs
new file mode 100644
index 00000000000..7ff3bc0dd2a
--- /dev/null
+++ b/src/test/ui/statics/auxiliary/static-methods-crate.rs
@@ -0,0 +1,29 @@
+#![crate_name="static_methods_crate"]
+#![crate_type = "lib"]
+
+pub trait read: Sized {
+    fn readMaybe(s: String) -> Option<Self>;
+}
+
+impl read for isize {
+    fn readMaybe(s: String) -> Option<isize> {
+        s.parse().ok()
+    }
+}
+
+impl read for bool {
+    fn readMaybe(s: String) -> Option<bool> {
+        match &*s {
+          "true" => Some(true),
+          "false" => Some(false),
+          _ => None
+        }
+    }
+}
+
+pub fn read<T:read>(s: String) -> T {
+    match read::readMaybe(s) {
+      Some(x) => x,
+      _ => panic!("read panicked!")
+    }
+}
diff --git a/src/test/ui/statics/auxiliary/static_fn_inline_xc_aux.rs b/src/test/ui/statics/auxiliary/static_fn_inline_xc_aux.rs
new file mode 100644
index 00000000000..8d0f7f61ced
--- /dev/null
+++ b/src/test/ui/statics/auxiliary/static_fn_inline_xc_aux.rs
@@ -0,0 +1,12 @@
+pub mod num {
+    pub trait Num2 {
+        fn from_int2(n: isize) -> Self;
+    }
+}
+
+pub mod f64 {
+    impl ::num::Num2 for f64 {
+        #[inline]
+        fn from_int2(n: isize) -> f64 { return n as f64;  }
+    }
+}
diff --git a/src/test/ui/statics/auxiliary/static_fn_trait_xc_aux.rs b/src/test/ui/statics/auxiliary/static_fn_trait_xc_aux.rs
new file mode 100644
index 00000000000..b8aed2c5f54
--- /dev/null
+++ b/src/test/ui/statics/auxiliary/static_fn_trait_xc_aux.rs
@@ -0,0 +1,11 @@
+pub mod num {
+    pub trait Num2 {
+        fn from_int2(n: isize) -> Self;
+    }
+}
+
+pub mod f64 {
+    impl ::num::Num2 for f64 {
+        fn from_int2(n: isize) -> f64 { return n as f64;  }
+    }
+}
diff --git a/src/test/ui/statics/auxiliary/static_mut_xc.rs b/src/test/ui/statics/auxiliary/static_mut_xc.rs
new file mode 100644
index 00000000000..264a2243adc
--- /dev/null
+++ b/src/test/ui/statics/auxiliary/static_mut_xc.rs
@@ -0,0 +1 @@
+pub static mut a: isize = 3;
diff --git a/src/test/ui/statics/static-fn-inline-xc.rs b/src/test/ui/statics/static-fn-inline-xc.rs
new file mode 100644
index 00000000000..a400b9c8d56
--- /dev/null
+++ b/src/test/ui/statics/static-fn-inline-xc.rs
@@ -0,0 +1,12 @@
+// run-pass
+// aux-build:static_fn_inline_xc_aux.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate static_fn_inline_xc_aux as mycore;
+
+use mycore::num;
+
+pub fn main() {
+    let _1: f64 = num::Num2::from_int2(1);
+}
diff --git a/src/test/ui/statics/static-fn-trait-xc.rs b/src/test/ui/statics/static-fn-trait-xc.rs
new file mode 100644
index 00000000000..1d3126128c9
--- /dev/null
+++ b/src/test/ui/statics/static-fn-trait-xc.rs
@@ -0,0 +1,12 @@
+// run-pass
+// aux-build:static_fn_trait_xc_aux.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate static_fn_trait_xc_aux as mycore;
+
+use mycore::num;
+
+pub fn main() {
+    let _1: f64 = num::Num2::from_int2(1);
+}
diff --git a/src/test/ui/statics/static-function-pointer-xc.rs b/src/test/ui/statics/static-function-pointer-xc.rs
new file mode 100644
index 00000000000..2d063a751ca
--- /dev/null
+++ b/src/test/ui/statics/static-function-pointer-xc.rs
@@ -0,0 +1,17 @@
+// run-pass
+// aux-build:static-function-pointer-aux.rs
+
+extern crate static_function_pointer_aux as aux;
+
+fn f(x: isize) -> isize { x }
+
+pub fn main() {
+    assert_eq!(aux::F(42), -42);
+    unsafe {
+        assert_eq!(aux::MutF(42), -42);
+        aux::MutF = f;
+        assert_eq!(aux::MutF(42), 42);
+        aux::MutF = aux::f;
+        assert_eq!(aux::MutF(42), -42);
+    }
+}
diff --git a/src/test/ui/statics/static-function-pointer.rs b/src/test/ui/statics/static-function-pointer.rs
new file mode 100644
index 00000000000..6c52dfecdec
--- /dev/null
+++ b/src/test/ui/statics/static-function-pointer.rs
@@ -0,0 +1,16 @@
+// run-pass
+
+fn f(x: isize) -> isize { x }
+fn g(x: isize) -> isize { 2 * x }
+
+static F: fn(isize) -> isize = f;
+static mut G: fn(isize) -> isize = f;
+
+pub fn main() {
+    assert_eq!(F(42), 42);
+    unsafe {
+        assert_eq!(G(42), 42);
+        G = g;
+        assert_eq!(G(42), 84);
+    }
+}
diff --git a/src/test/ui/statics/static-impl.rs b/src/test/ui/statics/static-impl.rs
new file mode 100644
index 00000000000..e7bdb38ee62
--- /dev/null
+++ b/src/test/ui/statics/static-impl.rs
@@ -0,0 +1,66 @@
+// run-pass
+#![allow(non_camel_case_types)]
+
+
+
+
+pub trait plus {
+    fn plus(&self) -> isize;
+}
+
+mod a {
+    use plus;
+    impl plus for usize { fn plus(&self) -> isize { *self as isize + 20 } }
+}
+
+mod b {
+    use plus;
+    impl plus for String { fn plus(&self) -> isize { 200 } }
+}
+
+trait uint_utils {
+    fn str(&self) -> String;
+    fn multi<F>(&self, f: F) where F: FnMut(usize);
+}
+
+impl uint_utils for usize {
+    fn str(&self) -> String {
+        self.to_string()
+    }
+    fn multi<F>(&self, mut f: F) where F: FnMut(usize) {
+        let mut c = 0_usize;
+        while c < *self { f(c); c += 1_usize; }
+    }
+}
+
+trait vec_utils<T> {
+    fn length_(&self, ) -> usize;
+    fn iter_<F>(&self, f: F) where F: FnMut(&T);
+    fn map_<U, F>(&self, f: F) -> Vec<U> where F: FnMut(&T) -> U;
+}
+
+impl<T> vec_utils<T> for Vec<T> {
+    fn length_(&self) -> usize { self.len() }
+    fn iter_<F>(&self, mut f: F) where F: FnMut(&T) { for x in self { f(x); } }
+    fn map_<U, F>(&self, mut f: F) -> Vec<U> where F: FnMut(&T) -> U {
+        let mut r = Vec::new();
+        for elt in self {
+            r.push(f(elt));
+        }
+        r
+    }
+}
+
+pub fn main() {
+    assert_eq!(10_usize.plus(), 30);
+    assert_eq!(("hi".to_string()).plus(), 200);
+
+    assert_eq!((vec![1]).length_().str(), "1".to_string());
+    let vect = vec![3, 4].map_(|a| *a + 4);
+    assert_eq!(vect[0], 7);
+    let vect = (vec![3, 4]).map_::<usize, _>(|a| *a as usize + 4_usize);
+    assert_eq!(vect[0], 7_usize);
+    let mut x = 0_usize;
+    10_usize.multi(|_n| x += 2_usize );
+    assert_eq!(x, 20_usize);
+}
diff --git a/src/test/ui/statics/static-method-in-trait-with-tps-intracrate.rs b/src/test/ui/statics/static-method-in-trait-with-tps-intracrate.rs
new file mode 100644
index 00000000000..cd3ccfee06f
--- /dev/null
+++ b/src/test/ui/statics/static-method-in-trait-with-tps-intracrate.rs
@@ -0,0 +1,28 @@
+// run-pass
+#![allow(dead_code)]
+
+trait Deserializer {
+    fn read_int(&self) -> isize;
+}
+
+trait Deserializable<D:Deserializer> {
+    fn deserialize(d: &D) -> Self;
+}
+
+impl<D:Deserializer> Deserializable<D> for isize {
+    fn deserialize(d: &D) -> isize {
+        return d.read_int();
+    }
+}
+
+struct FromThinAir { dummy: () }
+
+impl Deserializer for FromThinAir {
+    fn read_int(&self) -> isize { 22 }
+}
+
+pub fn main() {
+    let d = FromThinAir { dummy: () };
+    let i: isize = Deserializable::deserialize(&d);
+    assert_eq!(i, 22);
+}
diff --git a/src/test/ui/statics/static-method-xcrate.rs b/src/test/ui/statics/static-method-xcrate.rs
new file mode 100644
index 00000000000..1d1cb381095
--- /dev/null
+++ b/src/test/ui/statics/static-method-xcrate.rs
@@ -0,0 +1,13 @@
+// run-pass
+// aux-build:static-methods-crate.rs
+
+extern crate static_methods_crate;
+
+use static_methods_crate::read;
+
+pub fn main() {
+    let result: isize = read("5".to_string());
+    assert_eq!(result, 5);
+    assert_eq!(read::readMaybe("false".to_string()), Some(false));
+    assert_eq!(read::readMaybe("foo".to_string()), None::<bool>);
+}
diff --git a/src/test/ui/statics/static-methods-in-traits.rs b/src/test/ui/statics/static-methods-in-traits.rs
new file mode 100644
index 00000000000..ff76d4e4a20
--- /dev/null
+++ b/src/test/ui/statics/static-methods-in-traits.rs
@@ -0,0 +1,26 @@
+// run-pass
+
+mod a {
+    pub trait Foo {
+        fn foo() -> Self;
+    }
+
+    impl Foo for isize {
+        fn foo() -> isize {
+            3
+        }
+    }
+
+    impl Foo for usize {
+        fn foo() -> usize {
+            5
+        }
+    }
+}
+
+pub fn main() {
+    let x: isize = a::Foo::foo();
+    let y: usize = a::Foo::foo();
+    assert_eq!(x, 3);
+    assert_eq!(y, 5);
+}
diff --git a/src/test/ui/statics/static-methods-in-traits2.rs b/src/test/ui/statics/static-methods-in-traits2.rs
new file mode 100644
index 00000000000..2c43ff6a788
--- /dev/null
+++ b/src/test/ui/statics/static-methods-in-traits2.rs
@@ -0,0 +1,22 @@
+// run-pass
+// pretty-expanded FIXME #23616
+
+pub trait Number: NumConv {
+    fn from<T:Number>(n: T) -> Self;
+}
+
+impl Number for f64 {
+    fn from<T:Number>(n: T) -> f64 { n.to_float() }
+}
+
+pub trait NumConv {
+    fn to_float(&self) -> f64;
+}
+
+impl NumConv for f64 {
+    fn to_float(&self) -> f64 { *self }
+}
+
+pub fn main() {
+    let _: f64 = Number::from(0.0f64);
+}
diff --git a/src/test/ui/statics/static-mut-foreign.rs b/src/test/ui/statics/static-mut-foreign.rs
new file mode 100644
index 00000000000..5d6fa416b98
--- /dev/null
+++ b/src/test/ui/statics/static-mut-foreign.rs
@@ -0,0 +1,41 @@
+// run-pass
+// Constants (static variables) can be used to match in patterns, but mutable
+// statics cannot. This ensures that there's some form of error if this is
+// attempted.
+
+// ignore-wasm32-bare no libc to test ffi with
+
+#![feature(rustc_private)]
+
+extern crate libc;
+
+#[link(name = "rust_test_helpers", kind = "static")]
+extern {
+    static mut rust_dbg_static_mut: libc::c_int;
+    pub fn rust_dbg_static_mut_check_four();
+}
+
+unsafe fn static_bound(_: &'static libc::c_int) {}
+
+fn static_bound_set(a: &'static mut libc::c_int) {
+    *a = 3;
+}
+
+unsafe fn run() {
+    assert_eq!(rust_dbg_static_mut, 3);
+    rust_dbg_static_mut = 4;
+    assert_eq!(rust_dbg_static_mut, 4);
+    rust_dbg_static_mut_check_four();
+    rust_dbg_static_mut += 1;
+    assert_eq!(rust_dbg_static_mut, 5);
+    rust_dbg_static_mut *= 3;
+    assert_eq!(rust_dbg_static_mut, 15);
+    rust_dbg_static_mut = -3;
+    assert_eq!(rust_dbg_static_mut, -3);
+    static_bound(&rust_dbg_static_mut);
+    static_bound_set(&mut rust_dbg_static_mut);
+}
+
+pub fn main() {
+    unsafe { run() }
+}
diff --git a/src/test/ui/statics/static-mut-xc.rs b/src/test/ui/statics/static-mut-xc.rs
new file mode 100644
index 00000000000..1d172d26a59
--- /dev/null
+++ b/src/test/ui/statics/static-mut-xc.rs
@@ -0,0 +1,39 @@
+// run-pass
+#![allow(non_upper_case_globals)]
+
+// Constants (static variables) can be used to match in patterns, but mutable
+// statics cannot. This ensures that there's some form of error if this is
+// attempted.
+
+// aux-build:static_mut_xc.rs
+
+
+extern crate static_mut_xc;
+
+unsafe fn static_bound(_: &'static isize) {}
+
+fn static_bound_set(a: &'static mut isize) {
+    *a = 3;
+}
+
+unsafe fn run() {
+    assert_eq!(static_mut_xc::a, 3);
+    static_mut_xc::a = 4;
+    assert_eq!(static_mut_xc::a, 4);
+    static_mut_xc::a += 1;
+    assert_eq!(static_mut_xc::a, 5);
+    static_mut_xc::a *= 3;
+    assert_eq!(static_mut_xc::a, 15);
+    static_mut_xc::a = -3;
+    assert_eq!(static_mut_xc::a, -3);
+    static_bound(&static_mut_xc::a);
+    static_bound_set(&mut static_mut_xc::a);
+}
+
+pub fn main() {
+    unsafe { run() }
+}
+
+pub mod inner {
+    pub static mut a: isize = 4;
+}
diff --git a/src/test/ui/statics/static-recursive.rs b/src/test/ui/statics/static-recursive.rs
new file mode 100644
index 00000000000..95dadc81f81
--- /dev/null
+++ b/src/test/ui/statics/static-recursive.rs
@@ -0,0 +1,36 @@
+// run-pass
+static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
+
+struct StaticDoubleLinked {
+    prev: &'static StaticDoubleLinked,
+    next: &'static StaticDoubleLinked,
+    data: i32,
+    head: bool
+}
+
+static L1: StaticDoubleLinked = StaticDoubleLinked{prev: &L3, next: &L2, data: 1, head: true};
+static L2: StaticDoubleLinked = StaticDoubleLinked{prev: &L1, next: &L3, data: 2, head: false};
+static L3: StaticDoubleLinked = StaticDoubleLinked{prev: &L2, next: &L1, data: 3, head: false};
+
+
+pub fn main() {
+    unsafe { assert_eq!(S, *(S as *const *const u8)); }
+
+    let mut test_vec = Vec::new();
+    let mut cur = &L1;
+    loop {
+        test_vec.push(cur.data);
+        cur = cur.next;
+        if cur.head { break }
+    }
+    assert_eq!(&test_vec, &[1,2,3]);
+
+    let mut test_vec = Vec::new();
+    let mut cur = &L1;
+    loop {
+        cur = cur.prev;
+        test_vec.push(cur.data);
+        if cur.head { break }
+    }
+    assert_eq!(&test_vec, &[3,2,1]);
+}