From d09cf46d3247401f6c6ddd871ca79ac0a8bc2f2d Mon Sep 17 00:00:00 2001 From: Mark Simulacrum Date: Sun, 4 Jun 2017 07:02:05 -0600 Subject: [PATCH] Update UI tests to be platform independent --- src/librustc/middle/intrinsicck.rs | 2 +- src/test/ui/transmute/main.rs | 6 ++ src/test/ui/transmute/main.stderr | 16 +-- .../transmute-from-fn-item-types-error.rs | 11 ++- .../transmute-from-fn-item-types-error.stderr | 97 +++++++++++-------- .../ui/transmute/transmute-type-parameters.rs | 31 +++--- .../transmute-type-parameters.stderr | 50 +++++----- 7 files changed, 123 insertions(+), 90 deletions(-) diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index de92395ac69..f180ae53b8a 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -87,7 +87,7 @@ fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>) { // `Option` 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)) diff --git a/src/test/ui/transmute/main.rs b/src/test/ui/transmute/main.rs index 28cac90c69d..d5968a388dc 100644 --- a/src/test/ui/transmute/main.rs +++ b/src/test/ui/transmute/main.rs @@ -7,6 +7,12 @@ // , 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; diff --git a/src/test/ui/transmute/main.stderr b/src/test/ui/transmute/main.stderr index 2ae4252cfa2..c5d5a4ed8a6 100644 --- a/src/test/ui/transmute/main.stderr +++ b/src/test/ui/transmute/main.stderr @@ -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: >::T (size can vary because of ::T) = note: target type: >::T (size can vary because of ::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) diff --git a/src/test/ui/transmute/transmute-from-fn-item-types-error.rs b/src/test/ui/transmute/transmute-from-fn-item-types-error.rs index 808be8beede..98d2e1e3628 100644 --- a/src/test/ui/transmute/transmute-from-fn-item-types-error.rs +++ b/src/test/ui/transmute/transmute-from-fn-item-types-error.rs @@ -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) { +unsafe fn foo() -> (i32, *const (), Option) { 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::(main); + mem::transmute::(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::, usize>(Some(main)); + mem::transmute::, u32>(Some(main)); } fn main() { diff --git a/src/test/ui/transmute/transmute-from-fn-item-types-error.stderr b/src/test/ui/transmute/transmute-from-fn-item-types-error.stderr index efd60630aa2..61ee5cf6128 100644 --- a/src/test/ui/transmute/transmute-from-fn-item-types-error.stderr +++ b/src/test/ui/transmute/transmute-from-fn-item-types-error.stderr @@ -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) {foo} + = note: source type: unsafe fn() -> (i32, *const (), std::option::Option) {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) {foo} + = note: source type: unsafe fn() -> (i32, *const (), std::option::Option) {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::(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) {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) {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>(Some(baz)); +61 | mem::transmute::<_, Option>(Some(baz)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: source type: unsafe fn() {baz} = note: target type: std::option::Option = 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::, u32>(Some(main)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: std::option::Option (64 bits) + = note: target type: u32 (32 bits) + error: aborting due to previous error(s) diff --git a/src/test/ui/transmute/transmute-type-parameters.rs b/src/test/ui/transmute/transmute-type-parameters.rs index b6e7e32663e..fa83a10dc48 100644 --- a/src/test/ui/transmute/transmute-type-parameters.rs +++ b/src/test/ui/transmute/transmute-type-parameters.rs @@ -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(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(x: (T, isize)) { - let _: isize = transmute(x); -//~^ ERROR differently sized types: (T, isize) (size can vary because of T) to isize +unsafe fn g(x: (T, i32)) { + let _: i32 = transmute(x); +//~^ ERROR differently sized types: (T, i32) (size can vary because of T) to i32 } unsafe fn h(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 { @@ -32,8 +37,8 @@ struct Bad { } unsafe fn i(x: Bad) { - let _: isize = transmute(x); -//~^ ERROR differently sized types: Bad (size can vary because of T) to isize + let _: i32 = transmute(x); +//~^ ERROR differently sized types: Bad (size can vary because of T) to i32 } enum Worse { @@ -42,13 +47,13 @@ enum Worse { } unsafe fn j(x: Worse) { - let _: isize = transmute(x); -//~^ ERROR differently sized types: Worse (size can vary because of T) to isize + let _: i32 = transmute(x); +//~^ ERROR differently sized types: Worse (size can vary because of T) to i32 } unsafe fn k(x: Option) { - let _: isize = transmute(x); -//~^ ERROR differently sized types: std::option::Option (size can vary because of T) to isize + let _: i32 = transmute(x); +//~^ ERROR differently sized types: std::option::Option (size can vary because of T) to i32 } fn main() {} diff --git a/src/test/ui/transmute/transmute-type-parameters.stderr b/src/test/ui/transmute/transmute-type-parameters.stderr index 39f18efe97a..bb21cfd3e4c 100644 --- a/src/test/ui/transmute/transmute-type-parameters.stderr +++ b/src/test/ui/transmute/transmute-type-parameters.stderr @@ -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 (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 (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 (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)