]> git.lizzy.rs Git - rust.git/commitdiff
move a bunch of tests
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Thu, 28 Jan 2021 17:42:44 +0000 (18:42 +0100)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Thu, 28 Jan 2021 17:42:44 +0000 (18:42 +0100)
14 files changed:
src/test/ui/cast/fat-ptr-cast-rpass.rs [new file with mode: 0644]
src/test/ui/cast/fat-ptr-cast.rs [new file with mode: 0644]
src/test/ui/cast/fat-ptr-cast.stderr [new file with mode: 0644]
src/test/ui/cast/issue-17444.rs [new file with mode: 0644]
src/test/ui/cast/issue-17444.stderr [new file with mode: 0644]
src/test/ui/cast/unsupported-cast.rs [new file with mode: 0644]
src/test/ui/cast/unsupported-cast.stderr [new file with mode: 0644]
src/test/ui/fat-ptr-cast-rpass.rs [deleted file]
src/test/ui/fat-ptr-cast.rs [deleted file]
src/test/ui/fat-ptr-cast.stderr [deleted file]
src/test/ui/issues/issue-17444.rs [deleted file]
src/test/ui/issues/issue-17444.stderr [deleted file]
src/test/ui/unsupported-cast.rs [deleted file]
src/test/ui/unsupported-cast.stderr [deleted file]

diff --git a/src/test/ui/cast/fat-ptr-cast-rpass.rs b/src/test/ui/cast/fat-ptr-cast-rpass.rs
new file mode 100644 (file)
index 0000000..5f5e621
--- /dev/null
@@ -0,0 +1,41 @@
+// run-pass
+
+#![feature(raw)]
+
+use std::mem;
+use std::raw;
+
+trait Foo {
+    fn foo(&self) {}
+}
+
+struct Bar;
+
+impl Foo for Bar {}
+
+fn main() {
+    // Test we can turn a fat pointer to array back into a thin pointer.
+    let a: *const [i32] = &[1, 2, 3];
+    let b = a as *const [i32; 2];
+    unsafe {
+        assert_eq!(*b, [1, 2]);
+    }
+
+    // Test conversion to an address (usize).
+    let a: *const [i32; 3] = &[1, 2, 3];
+    let b: *const [i32] = a;
+    assert_eq!(a as usize, b as *const () as usize);
+
+    // And conversion to a void pointer/address for trait objects too.
+    let a: *mut dyn Foo = &mut Bar;
+    let b = a as *mut ();
+    let c = a as *const () as usize;
+    let d = unsafe {
+        let r: raw::TraitObject = mem::transmute(a);
+        r.data
+    };
+
+    assert_eq!(b, d);
+    assert_eq!(c, d as usize);
+
+}
diff --git a/src/test/ui/cast/fat-ptr-cast.rs b/src/test/ui/cast/fat-ptr-cast.rs
new file mode 100644 (file)
index 0000000..a0fad58
--- /dev/null
@@ -0,0 +1,24 @@
+trait Trait {}
+
+// Make sure casts between thin-pointer <-> fat pointer obey RFC401
+fn main() {
+    let a: &[i32] = &[1, 2, 3];
+    let b: Box<[i32]> = Box::new([1, 2, 3]);
+    let p = a as *const [i32];
+    let q = a.as_ptr();
+
+    a as usize; //~ ERROR casting
+    a as isize; //~ ERROR casting
+    a as i16; //~ ERROR casting `&[i32]` as `i16` is invalid
+    a as u32; //~ ERROR casting `&[i32]` as `u32` is invalid
+    b as usize; //~ ERROR non-primitive cast
+    p as usize;
+    //~^ ERROR casting
+
+    // #22955
+    q as *const [i32]; //~ ERROR cannot cast
+
+    // #21397
+    let t: *mut (dyn Trait + 'static) = 0 as *mut _; //~ ERROR casting
+    let mut fail: *const str = 0 as *const str; //~ ERROR casting
+}
diff --git a/src/test/ui/cast/fat-ptr-cast.stderr b/src/test/ui/cast/fat-ptr-cast.stderr
new file mode 100644 (file)
index 0000000..0b0c288
--- /dev/null
@@ -0,0 +1,68 @@
+error[E0606]: casting `&[i32]` as `usize` is invalid
+  --> $DIR/fat-ptr-cast.rs:10:5
+   |
+LL |     a as usize;
+   |     ^^^^^^^^^^
+   |
+   = help: cast through a raw pointer first
+
+error[E0606]: casting `&[i32]` as `isize` is invalid
+  --> $DIR/fat-ptr-cast.rs:11:5
+   |
+LL |     a as isize;
+   |     ^^^^^^^^^^
+   |
+   = help: cast through a raw pointer first
+
+error[E0606]: casting `&[i32]` as `i16` is invalid
+  --> $DIR/fat-ptr-cast.rs:12:5
+   |
+LL |     a as i16;
+   |     ^^^^^^^^
+   |
+   = help: cast through a raw pointer first
+
+error[E0606]: casting `&[i32]` as `u32` is invalid
+  --> $DIR/fat-ptr-cast.rs:13:5
+   |
+LL |     a as u32;
+   |     ^^^^^^^^
+   |
+   = help: cast through a raw pointer first
+
+error[E0605]: non-primitive cast: `Box<[i32]>` as `usize`
+  --> $DIR/fat-ptr-cast.rs:14:5
+   |
+LL |     b as usize;
+   |     ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
+
+error[E0606]: casting `*const [i32]` as `usize` is invalid
+  --> $DIR/fat-ptr-cast.rs:15:5
+   |
+LL |     p as usize;
+   |     ^^^^^^^^^^
+   |
+   = help: cast through a thin pointer first
+
+error[E0607]: cannot cast thin pointer `*const i32` to fat pointer `*const [i32]`
+  --> $DIR/fat-ptr-cast.rs:19:5
+   |
+LL |     q as *const [i32];
+   |     ^^^^^^^^^^^^^^^^^
+
+error[E0606]: casting `usize` as `*mut (dyn Trait + 'static)` is invalid
+  --> $DIR/fat-ptr-cast.rs:22:41
+   |
+LL |     let t: *mut (dyn Trait + 'static) = 0 as *mut _;
+   |                                         ^^^^^^^^^^^
+
+error[E0606]: casting `usize` as `*const str` is invalid
+  --> $DIR/fat-ptr-cast.rs:23:32
+   |
+LL |     let mut fail: *const str = 0 as *const str;
+   |                                ^^^^^^^^^^^^^^^
+
+error: aborting due to 9 previous errors
+
+Some errors have detailed explanations: E0605, E0606, E0607.
+For more information about an error, try `rustc --explain E0605`.
diff --git a/src/test/ui/cast/issue-17444.rs b/src/test/ui/cast/issue-17444.rs
new file mode 100644 (file)
index 0000000..906b443
--- /dev/null
@@ -0,0 +1,8 @@
+enum Test {
+    Foo = 0
+}
+
+fn main() {
+    let _x = Test::Foo as *const isize;
+    //~^ ERROR casting `Test` as `*const isize` is invalid
+}
diff --git a/src/test/ui/cast/issue-17444.stderr b/src/test/ui/cast/issue-17444.stderr
new file mode 100644 (file)
index 0000000..1097079
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0606]: casting `Test` as `*const isize` is invalid
+  --> $DIR/issue-17444.rs:6:14
+   |
+LL |     let _x = Test::Foo as *const isize;
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0606`.
diff --git a/src/test/ui/cast/unsupported-cast.rs b/src/test/ui/cast/unsupported-cast.rs
new file mode 100644 (file)
index 0000000..1384ecc
--- /dev/null
@@ -0,0 +1,5 @@
+struct A;
+
+fn main() {
+  println!("{:?}", 1.0 as *const A); //~ERROR  casting `f64` as `*const A` is invalid
+}
diff --git a/src/test/ui/cast/unsupported-cast.stderr b/src/test/ui/cast/unsupported-cast.stderr
new file mode 100644 (file)
index 0000000..56a375a
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0606]: casting `f64` as `*const A` is invalid
+  --> $DIR/unsupported-cast.rs:4:20
+   |
+LL |   println!("{:?}", 1.0 as *const A);
+   |                    ^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0606`.
diff --git a/src/test/ui/fat-ptr-cast-rpass.rs b/src/test/ui/fat-ptr-cast-rpass.rs
deleted file mode 100644 (file)
index 5f5e621..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// run-pass
-
-#![feature(raw)]
-
-use std::mem;
-use std::raw;
-
-trait Foo {
-    fn foo(&self) {}
-}
-
-struct Bar;
-
-impl Foo for Bar {}
-
-fn main() {
-    // Test we can turn a fat pointer to array back into a thin pointer.
-    let a: *const [i32] = &[1, 2, 3];
-    let b = a as *const [i32; 2];
-    unsafe {
-        assert_eq!(*b, [1, 2]);
-    }
-
-    // Test conversion to an address (usize).
-    let a: *const [i32; 3] = &[1, 2, 3];
-    let b: *const [i32] = a;
-    assert_eq!(a as usize, b as *const () as usize);
-
-    // And conversion to a void pointer/address for trait objects too.
-    let a: *mut dyn Foo = &mut Bar;
-    let b = a as *mut ();
-    let c = a as *const () as usize;
-    let d = unsafe {
-        let r: raw::TraitObject = mem::transmute(a);
-        r.data
-    };
-
-    assert_eq!(b, d);
-    assert_eq!(c, d as usize);
-
-}
diff --git a/src/test/ui/fat-ptr-cast.rs b/src/test/ui/fat-ptr-cast.rs
deleted file mode 100644 (file)
index a0fad58..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-trait Trait {}
-
-// Make sure casts between thin-pointer <-> fat pointer obey RFC401
-fn main() {
-    let a: &[i32] = &[1, 2, 3];
-    let b: Box<[i32]> = Box::new([1, 2, 3]);
-    let p = a as *const [i32];
-    let q = a.as_ptr();
-
-    a as usize; //~ ERROR casting
-    a as isize; //~ ERROR casting
-    a as i16; //~ ERROR casting `&[i32]` as `i16` is invalid
-    a as u32; //~ ERROR casting `&[i32]` as `u32` is invalid
-    b as usize; //~ ERROR non-primitive cast
-    p as usize;
-    //~^ ERROR casting
-
-    // #22955
-    q as *const [i32]; //~ ERROR cannot cast
-
-    // #21397
-    let t: *mut (dyn Trait + 'static) = 0 as *mut _; //~ ERROR casting
-    let mut fail: *const str = 0 as *const str; //~ ERROR casting
-}
diff --git a/src/test/ui/fat-ptr-cast.stderr b/src/test/ui/fat-ptr-cast.stderr
deleted file mode 100644 (file)
index 0b0c288..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-error[E0606]: casting `&[i32]` as `usize` is invalid
-  --> $DIR/fat-ptr-cast.rs:10:5
-   |
-LL |     a as usize;
-   |     ^^^^^^^^^^
-   |
-   = help: cast through a raw pointer first
-
-error[E0606]: casting `&[i32]` as `isize` is invalid
-  --> $DIR/fat-ptr-cast.rs:11:5
-   |
-LL |     a as isize;
-   |     ^^^^^^^^^^
-   |
-   = help: cast through a raw pointer first
-
-error[E0606]: casting `&[i32]` as `i16` is invalid
-  --> $DIR/fat-ptr-cast.rs:12:5
-   |
-LL |     a as i16;
-   |     ^^^^^^^^
-   |
-   = help: cast through a raw pointer first
-
-error[E0606]: casting `&[i32]` as `u32` is invalid
-  --> $DIR/fat-ptr-cast.rs:13:5
-   |
-LL |     a as u32;
-   |     ^^^^^^^^
-   |
-   = help: cast through a raw pointer first
-
-error[E0605]: non-primitive cast: `Box<[i32]>` as `usize`
-  --> $DIR/fat-ptr-cast.rs:14:5
-   |
-LL |     b as usize;
-   |     ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
-
-error[E0606]: casting `*const [i32]` as `usize` is invalid
-  --> $DIR/fat-ptr-cast.rs:15:5
-   |
-LL |     p as usize;
-   |     ^^^^^^^^^^
-   |
-   = help: cast through a thin pointer first
-
-error[E0607]: cannot cast thin pointer `*const i32` to fat pointer `*const [i32]`
-  --> $DIR/fat-ptr-cast.rs:19:5
-   |
-LL |     q as *const [i32];
-   |     ^^^^^^^^^^^^^^^^^
-
-error[E0606]: casting `usize` as `*mut (dyn Trait + 'static)` is invalid
-  --> $DIR/fat-ptr-cast.rs:22:41
-   |
-LL |     let t: *mut (dyn Trait + 'static) = 0 as *mut _;
-   |                                         ^^^^^^^^^^^
-
-error[E0606]: casting `usize` as `*const str` is invalid
-  --> $DIR/fat-ptr-cast.rs:23:32
-   |
-LL |     let mut fail: *const str = 0 as *const str;
-   |                                ^^^^^^^^^^^^^^^
-
-error: aborting due to 9 previous errors
-
-Some errors have detailed explanations: E0605, E0606, E0607.
-For more information about an error, try `rustc --explain E0605`.
diff --git a/src/test/ui/issues/issue-17444.rs b/src/test/ui/issues/issue-17444.rs
deleted file mode 100644 (file)
index 906b443..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-enum Test {
-    Foo = 0
-}
-
-fn main() {
-    let _x = Test::Foo as *const isize;
-    //~^ ERROR casting `Test` as `*const isize` is invalid
-}
diff --git a/src/test/ui/issues/issue-17444.stderr b/src/test/ui/issues/issue-17444.stderr
deleted file mode 100644 (file)
index 1097079..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0606]: casting `Test` as `*const isize` is invalid
-  --> $DIR/issue-17444.rs:6:14
-   |
-LL |     let _x = Test::Foo as *const isize;
-   |              ^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0606`.
diff --git a/src/test/ui/unsupported-cast.rs b/src/test/ui/unsupported-cast.rs
deleted file mode 100644 (file)
index cb6a57a..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// error-pattern:casting
-
-struct A;
-
-fn main() {
-  println!("{:?}", 1.0 as *const A); // Can't cast float to foreign.
-}
diff --git a/src/test/ui/unsupported-cast.stderr b/src/test/ui/unsupported-cast.stderr
deleted file mode 100644 (file)
index 63e7713..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0606]: casting `f64` as `*const A` is invalid
-  --> $DIR/unsupported-cast.rs:6:20
-   |
-LL |   println!("{:?}", 1.0 as *const A); // Can't cast float to foreign.
-   |                    ^^^^^^^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0606`.