Update UI tests to be platform independent
This commit is contained in:
parent
effa869cab
commit
d09cf46d32
@ -87,7 +87,7 @@ fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>) {
|
||||
// `Option<typeof(function)>` to present a clearer error.
|
||||
let from = unpack_option_like(self.tcx.global_tcx(), from);
|
||||
if let (&ty::TyFnDef(..), SizeSkeleton::Known(size_to)) = (&from.sty, sk_to) {
|
||||
if size_to == Pointer.size(self.tcx) => {
|
||||
if size_to == Pointer.size(self.tcx) {
|
||||
struct_span_err!(self.tcx.sess, span, E0591,
|
||||
"can't transmute zero-sized type")
|
||||
.note(&format!("source type: {}", from))
|
||||
|
@ -7,6 +7,12 @@
|
||||
// <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.
|
||||
|
||||
// ignore-x86
|
||||
// ignore-arm
|
||||
// ignore-emscripten
|
||||
// ignore 32-bit platforms (test output is different)
|
||||
|
||||
#![feature(untagged_unions)]
|
||||
use std::mem::transmute;
|
||||
|
||||
|
@ -1,34 +1,34 @@
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/main.rs:20:5
|
||||
--> $DIR/main.rs:26:5
|
||||
|
|
||||
20 | transmute(x) //~ ERROR transmute called with types of different sizes
|
||||
26 | transmute(x) //~ ERROR transmute called with types of different sizes
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: <C as TypeConstructor<'a>>::T (size can vary because of <C as TypeConstructor>::T)
|
||||
= note: target type: <C as TypeConstructor<'b>>::T (size can vary because of <C as TypeConstructor>::T)
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/main.rs:24:17
|
||||
--> $DIR/main.rs:30:17
|
||||
|
|
||||
24 | let x: u8 = transmute(10u16); //~ ERROR transmute called with types of different sizes
|
||||
30 | let x: u8 = transmute(10u16); //~ ERROR transmute called with types of different sizes
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: u16 (16 bits)
|
||||
= note: target type: u8 (8 bits)
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/main.rs:28:17
|
||||
--> $DIR/main.rs:34:17
|
||||
|
|
||||
28 | let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
|
||||
34 | let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: &str (128 bits)
|
||||
= note: target type: u8 (8 bits)
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/main.rs:33:18
|
||||
--> $DIR/main.rs:39:18
|
||||
|
|
||||
33 | let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes
|
||||
39 | let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: i32 (32 bits)
|
||||
|
@ -8,9 +8,14 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-x86
|
||||
// ignore-arm
|
||||
// ignore-emscripten
|
||||
// ignore 32-bit platforms (test output is different)
|
||||
|
||||
use std::mem;
|
||||
|
||||
unsafe fn foo() -> (isize, *const (), Option<fn()>) {
|
||||
unsafe fn foo() -> (i32, *const (), Option<fn()>) {
|
||||
let i = mem::transmute(bar);
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
@ -41,7 +46,7 @@ unsafe fn bar() {
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
// No error if a coercion would otherwise occur.
|
||||
mem::transmute::<fn(), usize>(main);
|
||||
mem::transmute::<fn(), u32>(main);
|
||||
}
|
||||
|
||||
unsafe fn baz() {
|
||||
@ -58,7 +63,7 @@ unsafe fn baz() {
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
// No error if a coercion would otherwise occur.
|
||||
mem::transmute::<Option<fn()>, usize>(Some(main));
|
||||
mem::transmute::<Option<fn()>, u32>(Some(main));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,27 +1,26 @@
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:14:13
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:19:13
|
||||
|
|
||||
14 | let i = mem::transmute(bar);
|
||||
19 | let i = mem::transmute(bar);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() {bar}
|
||||
= note: target type: isize
|
||||
= help: cast with `as` to a pointer instead
|
||||
= note: source type: unsafe fn() {bar} (0 bits)
|
||||
= note: target type: i32 (32 bits)
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:18:13
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:23:13
|
||||
|
|
||||
18 | let p = mem::transmute(foo);
|
||||
23 | let p = mem::transmute(foo);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() -> (isize, *const (), std::option::Option<fn()>) {foo}
|
||||
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
|
||||
= note: target type: *const ()
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:22:14
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:27:14
|
||||
|
|
||||
22 | let of = mem::transmute(main);
|
||||
27 | let of = mem::transmute(main);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: fn() {main}
|
||||
@ -29,28 +28,57 @@ error[E0591]: can't transmute zero-sized type
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:31:5
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:36:5
|
||||
|
|
||||
31 | mem::transmute::<_, u8>(main);
|
||||
36 | mem::transmute::<_, u8>(main);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: fn() {main} (0 bits)
|
||||
= note: target type: u8 (8 bits)
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:35:5
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:40:5
|
||||
|
|
||||
35 | mem::transmute::<_, *mut ()>(foo);
|
||||
40 | mem::transmute::<_, *mut ()>(foo);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() -> (isize, *const (), std::option::Option<fn()>) {foo}
|
||||
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
|
||||
= note: target type: *mut ()
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:39:5
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:44:5
|
||||
|
|
||||
39 | mem::transmute::<_, fn()>(bar);
|
||||
44 | mem::transmute::<_, fn()>(bar);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() {bar}
|
||||
= note: target type: fn()
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:49:5
|
||||
|
|
||||
49 | mem::transmute::<fn(), u32>(main);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: fn() (64 bits)
|
||||
= note: target type: u32 (32 bits)
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:53:5
|
||||
|
|
||||
53 | mem::transmute::<_, *mut ()>(Some(foo));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
|
||||
= note: target type: *mut ()
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:57:5
|
||||
|
|
||||
57 | mem::transmute::<_, fn()>(Some(bar));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() {bar}
|
||||
@ -58,34 +86,23 @@ error[E0591]: can't transmute zero-sized type
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:48:5
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:61:5
|
||||
|
|
||||
48 | mem::transmute::<_, *mut ()>(Some(foo));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() -> (isize, *const (), std::option::Option<fn()>) {foo}
|
||||
= note: target type: *mut ()
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:52:5
|
||||
|
|
||||
52 | mem::transmute::<_, fn()>(Some(bar));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() {bar}
|
||||
= note: target type: fn()
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0591]: can't transmute zero-sized type
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:56:5
|
||||
|
|
||||
56 | mem::transmute::<_, Option<fn()>>(Some(baz));
|
||||
61 | mem::transmute::<_, Option<fn()>>(Some(baz));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: unsafe fn() {baz}
|
||||
= note: target type: std::option::Option<fn()>
|
||||
= help: cast with `as` to a pointer instead
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-from-fn-item-types-error.rs:66:5
|
||||
|
|
||||
66 | mem::transmute::<Option<fn()>, u32>(Some(main));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: source type: std::option::Option<fn()> (64 bits)
|
||||
= note: target type: u32 (32 bits)
|
||||
|
||||
error: aborting due to previous error(s)
|
||||
|
||||
|
@ -8,23 +8,28 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-x86
|
||||
// ignore-arm
|
||||
// ignore-emscripten
|
||||
// ignore 32-bit platforms (test output is different)
|
||||
|
||||
// Tests that `transmute` cannot be called on type parameters.
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
unsafe fn f<T>(x: T) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: T (size can vary) to isize
|
||||
let _: i32 = transmute(x);
|
||||
//~^ ERROR differently sized types: T (size can vary) to i32
|
||||
}
|
||||
|
||||
unsafe fn g<T>(x: (T, isize)) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: (T, isize) (size can vary because of T) to isize
|
||||
unsafe fn g<T>(x: (T, i32)) {
|
||||
let _: i32 = transmute(x);
|
||||
//~^ ERROR differently sized types: (T, i32) (size can vary because of T) to i32
|
||||
}
|
||||
|
||||
unsafe fn h<T>(x: [T; 10]) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: [T; 10] (size can vary because of T) to isize
|
||||
let _: i32 = transmute(x);
|
||||
//~^ ERROR differently sized types: [T; 10] (size can vary because of T) to i32
|
||||
}
|
||||
|
||||
struct Bad<T> {
|
||||
@ -32,8 +37,8 @@ struct Bad<T> {
|
||||
}
|
||||
|
||||
unsafe fn i<T>(x: Bad<T>) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: Bad<T> (size can vary because of T) to isize
|
||||
let _: i32 = transmute(x);
|
||||
//~^ ERROR differently sized types: Bad<T> (size can vary because of T) to i32
|
||||
}
|
||||
|
||||
enum Worse<T> {
|
||||
@ -42,13 +47,13 @@ enum Worse<T> {
|
||||
}
|
||||
|
||||
unsafe fn j<T>(x: Worse<T>) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: Worse<T> (size can vary because of T) to isize
|
||||
let _: i32 = transmute(x);
|
||||
//~^ ERROR differently sized types: Worse<T> (size can vary because of T) to i32
|
||||
}
|
||||
|
||||
unsafe fn k<T>(x: Option<T>) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: std::option::Option<T> (size can vary because of T) to isize
|
||||
let _: i32 = transmute(x);
|
||||
//~^ ERROR differently sized types: std::option::Option<T> (size can vary because of T) to i32
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,56 +1,56 @@
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-type-parameters.rs:16:20
|
||||
--> $DIR/transmute-type-parameters.rs:21:18
|
||||
|
|
||||
16 | let _: isize = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
21 | let _: i32 = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: T (this type's size can vary)
|
||||
= note: target type: isize (64 bits)
|
||||
= note: target type: i32 (32 bits)
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-type-parameters.rs:21:20
|
||||
--> $DIR/transmute-type-parameters.rs:26:18
|
||||
|
|
||||
21 | let _: isize = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
26 | let _: i32 = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: (T, isize) (size can vary because of T)
|
||||
= note: target type: isize (64 bits)
|
||||
= note: source type: (T, i32) (size can vary because of T)
|
||||
= note: target type: i32 (32 bits)
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-type-parameters.rs:26:20
|
||||
--> $DIR/transmute-type-parameters.rs:31:18
|
||||
|
|
||||
26 | let _: isize = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
31 | let _: i32 = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: [T; 10] (size can vary because of T)
|
||||
= note: target type: isize (64 bits)
|
||||
= note: target type: i32 (32 bits)
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-type-parameters.rs:35:20
|
||||
--> $DIR/transmute-type-parameters.rs:40:18
|
||||
|
|
||||
35 | let _: isize = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
40 | let _: i32 = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: Bad<T> (size can vary because of T)
|
||||
= note: target type: isize (64 bits)
|
||||
= note: target type: i32 (32 bits)
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-type-parameters.rs:45:20
|
||||
--> $DIR/transmute-type-parameters.rs:50:18
|
||||
|
|
||||
45 | let _: isize = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
50 | let _: i32 = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: Worse<T> (size can vary because of T)
|
||||
= note: target type: isize (64 bits)
|
||||
= note: target type: i32 (32 bits)
|
||||
|
||||
error[E0512]: transmute called with types of different sizes
|
||||
--> $DIR/transmute-type-parameters.rs:50:20
|
||||
--> $DIR/transmute-type-parameters.rs:55:18
|
||||
|
|
||||
50 | let _: isize = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
55 | let _: i32 = transmute(x);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: source type: std::option::Option<T> (size can vary because of T)
|
||||
= note: target type: isize (64 bits)
|
||||
= note: target type: i32 (32 bits)
|
||||
|
||||
error: aborting due to previous error(s)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user