--- /dev/null
+// 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);
+
+}
--- /dev/null
+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
+}
--- /dev/null
+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`.
--- /dev/null
+enum Test {
+ Foo = 0
+}
+
+fn main() {
+ let _x = Test::Foo as *const isize;
+ //~^ ERROR casting `Test` as `*const isize` is invalid
+}
--- /dev/null
+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`.
--- /dev/null
+struct A;
+
+fn main() {
+ println!("{:?}", 1.0 as *const A); //~ERROR casting `f64` as `*const A` is invalid
+}
--- /dev/null
+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`.
+++ /dev/null
-// 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);
-
-}
+++ /dev/null
-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
-}
+++ /dev/null
-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`.
+++ /dev/null
-enum Test {
- Foo = 0
-}
-
-fn main() {
- let _x = Test::Foo as *const isize;
- //~^ ERROR casting `Test` as `*const isize` is invalid
-}
+++ /dev/null
-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`.
+++ /dev/null
-// error-pattern:casting
-
-struct A;
-
-fn main() {
- println!("{:?}", 1.0 as *const A); // Can't cast float to foreign.
-}
+++ /dev/null
-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`.