Skip to content

Commit d09cf46

Browse files
Update UI tests to be platform independent
1 parent effa869 commit d09cf46

7 files changed

+108
-75
lines changed

src/librustc/middle/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
8787
// `Option<typeof(function)>` to present a clearer error.
8888
let from = unpack_option_like(self.tcx.global_tcx(), from);
8989
if let (&ty::TyFnDef(..), SizeSkeleton::Known(size_to)) = (&from.sty, sk_to) {
90-
if size_to == Pointer.size(self.tcx) => {
90+
if size_to == Pointer.size(self.tcx) {
9191
struct_span_err!(self.tcx.sess, span, E0591,
9292
"can't transmute zero-sized type")
9393
.note(&format!("source type: {}", from))

src/test/ui/transmute/main.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10+
11+
// ignore-x86
12+
// ignore-arm
13+
// ignore-emscripten
14+
// ignore 32-bit platforms (test output is different)
15+
1016
#![feature(untagged_unions)]
1117
use std::mem::transmute;
1218

src/test/ui/transmute/main.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
error[E0512]: transmute called with types of different sizes
2-
--> $DIR/main.rs:20:5
2+
--> $DIR/main.rs:26:5
33
|
4-
20 | transmute(x) //~ ERROR transmute called with types of different sizes
4+
26 | transmute(x) //~ ERROR transmute called with types of different sizes
55
| ^^^^^^^^^
66
|
77
= note: source type: <C as TypeConstructor<'a>>::T (size can vary because of <C as TypeConstructor>::T)
88
= note: target type: <C as TypeConstructor<'b>>::T (size can vary because of <C as TypeConstructor>::T)
99

1010
error[E0512]: transmute called with types of different sizes
11-
--> $DIR/main.rs:24:17
11+
--> $DIR/main.rs:30:17
1212
|
13-
24 | let x: u8 = transmute(10u16); //~ ERROR transmute called with types of different sizes
13+
30 | let x: u8 = transmute(10u16); //~ ERROR transmute called with types of different sizes
1414
| ^^^^^^^^^
1515
|
1616
= note: source type: u16 (16 bits)
1717
= note: target type: u8 (8 bits)
1818

1919
error[E0512]: transmute called with types of different sizes
20-
--> $DIR/main.rs:28:17
20+
--> $DIR/main.rs:34:17
2121
|
22-
28 | let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
22+
34 | let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
2323
| ^^^^^^^^^
2424
|
2525
= note: source type: &str (128 bits)
2626
= note: target type: u8 (8 bits)
2727

2828
error[E0512]: transmute called with types of different sizes
29-
--> $DIR/main.rs:33:18
29+
--> $DIR/main.rs:39:18
3030
|
31-
33 | let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes
31+
39 | let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes
3232
| ^^^^^^^^^
3333
|
3434
= note: source type: i32 (32 bits)

src/test/ui/transmute/transmute-from-fn-item-types-error.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-x86
12+
// ignore-arm
13+
// ignore-emscripten
14+
// ignore 32-bit platforms (test output is different)
15+
1116
use std::mem;
1217

13-
unsafe fn foo() -> (isize, *const (), Option<fn()>) {
18+
unsafe fn foo() -> (i32, *const (), Option<fn()>) {
1419
let i = mem::transmute(bar);
1520
//~^ ERROR is zero-sized and can't be transmuted
1621
//~^^ NOTE cast with `as` to a pointer instead
@@ -41,7 +46,7 @@ unsafe fn bar() {
4146
//~^^ NOTE cast with `as` to a pointer instead
4247

4348
// No error if a coercion would otherwise occur.
44-
mem::transmute::<fn(), usize>(main);
49+
mem::transmute::<fn(), u32>(main);
4550
}
4651

4752
unsafe fn baz() {
@@ -58,7 +63,7 @@ unsafe fn baz() {
5863
//~^^ NOTE cast with `as` to a pointer instead
5964

6065
// No error if a coercion would otherwise occur.
61-
mem::transmute::<Option<fn()>, usize>(Some(main));
66+
mem::transmute::<Option<fn()>, u32>(Some(main));
6267
}
6368

6469
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,108 @@
1-
error[E0591]: can't transmute zero-sized type
2-
--> $DIR/transmute-from-fn-item-types-error.rs:14:13
1+
error[E0512]: transmute called with types of different sizes
2+
--> $DIR/transmute-from-fn-item-types-error.rs:19:13
33
|
4-
14 | let i = mem::transmute(bar);
4+
19 | let i = mem::transmute(bar);
55
| ^^^^^^^^^^^^^^
66
|
7-
= note: source type: unsafe fn() {bar}
8-
= note: target type: isize
9-
= help: cast with `as` to a pointer instead
7+
= note: source type: unsafe fn() {bar} (0 bits)
8+
= note: target type: i32 (32 bits)
109

1110
error[E0591]: can't transmute zero-sized type
12-
--> $DIR/transmute-from-fn-item-types-error.rs:18:13
11+
--> $DIR/transmute-from-fn-item-types-error.rs:23:13
1312
|
14-
18 | let p = mem::transmute(foo);
13+
23 | let p = mem::transmute(foo);
1514
| ^^^^^^^^^^^^^^
1615
|
17-
= note: source type: unsafe fn() -> (isize, *const (), std::option::Option<fn()>) {foo}
16+
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
1817
= note: target type: *const ()
1918
= help: cast with `as` to a pointer instead
2019

2120
error[E0591]: can't transmute zero-sized type
22-
--> $DIR/transmute-from-fn-item-types-error.rs:22:14
21+
--> $DIR/transmute-from-fn-item-types-error.rs:27:14
2322
|
24-
22 | let of = mem::transmute(main);
23+
27 | let of = mem::transmute(main);
2524
| ^^^^^^^^^^^^^^
2625
|
2726
= note: source type: fn() {main}
2827
= note: target type: std::option::Option<fn()>
2928
= help: cast with `as` to a pointer instead
3029

3130
error[E0512]: transmute called with types of different sizes
32-
--> $DIR/transmute-from-fn-item-types-error.rs:31:5
31+
--> $DIR/transmute-from-fn-item-types-error.rs:36:5
3332
|
34-
31 | mem::transmute::<_, u8>(main);
33+
36 | mem::transmute::<_, u8>(main);
3534
| ^^^^^^^^^^^^^^^^^^^^^^^
3635
|
3736
= note: source type: fn() {main} (0 bits)
3837
= note: target type: u8 (8 bits)
3938

4039
error[E0591]: can't transmute zero-sized type
41-
--> $DIR/transmute-from-fn-item-types-error.rs:35:5
40+
--> $DIR/transmute-from-fn-item-types-error.rs:40:5
4241
|
43-
35 | mem::transmute::<_, *mut ()>(foo);
42+
40 | mem::transmute::<_, *mut ()>(foo);
4443
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4544
|
46-
= note: source type: unsafe fn() -> (isize, *const (), std::option::Option<fn()>) {foo}
45+
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
4746
= note: target type: *mut ()
4847
= help: cast with `as` to a pointer instead
4948

5049
error[E0591]: can't transmute zero-sized type
51-
--> $DIR/transmute-from-fn-item-types-error.rs:39:5
50+
--> $DIR/transmute-from-fn-item-types-error.rs:44:5
5251
|
53-
39 | mem::transmute::<_, fn()>(bar);
52+
44 | mem::transmute::<_, fn()>(bar);
5453
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5554
|
5655
= note: source type: unsafe fn() {bar}
5756
= note: target type: fn()
5857
= help: cast with `as` to a pointer instead
5958

59+
error[E0512]: transmute called with types of different sizes
60+
--> $DIR/transmute-from-fn-item-types-error.rs:49:5
61+
|
62+
49 | mem::transmute::<fn(), u32>(main);
63+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
64+
|
65+
= note: source type: fn() (64 bits)
66+
= note: target type: u32 (32 bits)
67+
6068
error[E0591]: can't transmute zero-sized type
61-
--> $DIR/transmute-from-fn-item-types-error.rs:48:5
69+
--> $DIR/transmute-from-fn-item-types-error.rs:53:5
6270
|
63-
48 | mem::transmute::<_, *mut ()>(Some(foo));
71+
53 | mem::transmute::<_, *mut ()>(Some(foo));
6472
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6573
|
66-
= note: source type: unsafe fn() -> (isize, *const (), std::option::Option<fn()>) {foo}
74+
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
6775
= note: target type: *mut ()
6876
= help: cast with `as` to a pointer instead
6977

7078
error[E0591]: can't transmute zero-sized type
71-
--> $DIR/transmute-from-fn-item-types-error.rs:52:5
79+
--> $DIR/transmute-from-fn-item-types-error.rs:57:5
7280
|
73-
52 | mem::transmute::<_, fn()>(Some(bar));
81+
57 | mem::transmute::<_, fn()>(Some(bar));
7482
| ^^^^^^^^^^^^^^^^^^^^^^^^^
7583
|
7684
= note: source type: unsafe fn() {bar}
7785
= note: target type: fn()
7886
= help: cast with `as` to a pointer instead
7987

8088
error[E0591]: can't transmute zero-sized type
81-
--> $DIR/transmute-from-fn-item-types-error.rs:56:5
89+
--> $DIR/transmute-from-fn-item-types-error.rs:61:5
8290
|
83-
56 | mem::transmute::<_, Option<fn()>>(Some(baz));
91+
61 | mem::transmute::<_, Option<fn()>>(Some(baz));
8492
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8593
|
8694
= note: source type: unsafe fn() {baz}
8795
= note: target type: std::option::Option<fn()>
8896
= help: cast with `as` to a pointer instead
8997

98+
error[E0512]: transmute called with types of different sizes
99+
--> $DIR/transmute-from-fn-item-types-error.rs:66:5
100+
|
101+
66 | mem::transmute::<Option<fn()>, u32>(Some(main));
102+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103+
|
104+
= note: source type: std::option::Option<fn()> (64 bits)
105+
= note: target type: u32 (32 bits)
106+
90107
error: aborting due to previous error(s)
91108

src/test/ui/transmute/transmute-type-parameters.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,37 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-x86
12+
// ignore-arm
13+
// ignore-emscripten
14+
// ignore 32-bit platforms (test output is different)
15+
1116
// Tests that `transmute` cannot be called on type parameters.
1217

1318
use std::mem::transmute;
1419

1520
unsafe fn f<T>(x: T) {
16-
let _: isize = transmute(x);
17-
//~^ ERROR differently sized types: T (size can vary) to isize
21+
let _: i32 = transmute(x);
22+
//~^ ERROR differently sized types: T (size can vary) to i32
1823
}
1924

20-
unsafe fn g<T>(x: (T, isize)) {
21-
let _: isize = transmute(x);
22-
//~^ ERROR differently sized types: (T, isize) (size can vary because of T) to isize
25+
unsafe fn g<T>(x: (T, i32)) {
26+
let _: i32 = transmute(x);
27+
//~^ ERROR differently sized types: (T, i32) (size can vary because of T) to i32
2328
}
2429

2530
unsafe fn h<T>(x: [T; 10]) {
26-
let _: isize = transmute(x);
27-
//~^ ERROR differently sized types: [T; 10] (size can vary because of T) to isize
31+
let _: i32 = transmute(x);
32+
//~^ ERROR differently sized types: [T; 10] (size can vary because of T) to i32
2833
}
2934

3035
struct Bad<T> {
3136
f: T,
3237
}
3338

3439
unsafe fn i<T>(x: Bad<T>) {
35-
let _: isize = transmute(x);
36-
//~^ ERROR differently sized types: Bad<T> (size can vary because of T) to isize
40+
let _: i32 = transmute(x);
41+
//~^ ERROR differently sized types: Bad<T> (size can vary because of T) to i32
3742
}
3843

3944
enum Worse<T> {
@@ -42,13 +47,13 @@ enum Worse<T> {
4247
}
4348

4449
unsafe fn j<T>(x: Worse<T>) {
45-
let _: isize = transmute(x);
46-
//~^ ERROR differently sized types: Worse<T> (size can vary because of T) to isize
50+
let _: i32 = transmute(x);
51+
//~^ ERROR differently sized types: Worse<T> (size can vary because of T) to i32
4752
}
4853

4954
unsafe fn k<T>(x: Option<T>) {
50-
let _: isize = transmute(x);
51-
//~^ ERROR differently sized types: std::option::Option<T> (size can vary because of T) to isize
55+
let _: i32 = transmute(x);
56+
//~^ ERROR differently sized types: std::option::Option<T> (size can vary because of T) to i32
5257
}
5358

5459
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
error[E0512]: transmute called with types of different sizes
2-
--> $DIR/transmute-type-parameters.rs:16:20
2+
--> $DIR/transmute-type-parameters.rs:21:18
33
|
4-
16 | let _: isize = transmute(x);
5-
| ^^^^^^^^^
4+
21 | let _: i32 = transmute(x);
5+
| ^^^^^^^^^
66
|
77
= note: source type: T (this type's size can vary)
8-
= note: target type: isize (64 bits)
8+
= note: target type: i32 (32 bits)
99

1010
error[E0512]: transmute called with types of different sizes
11-
--> $DIR/transmute-type-parameters.rs:21:20
11+
--> $DIR/transmute-type-parameters.rs:26:18
1212
|
13-
21 | let _: isize = transmute(x);
14-
| ^^^^^^^^^
13+
26 | let _: i32 = transmute(x);
14+
| ^^^^^^^^^
1515
|
16-
= note: source type: (T, isize) (size can vary because of T)
17-
= note: target type: isize (64 bits)
16+
= note: source type: (T, i32) (size can vary because of T)
17+
= note: target type: i32 (32 bits)
1818

1919
error[E0512]: transmute called with types of different sizes
20-
--> $DIR/transmute-type-parameters.rs:26:20
20+
--> $DIR/transmute-type-parameters.rs:31:18
2121
|
22-
26 | let _: isize = transmute(x);
23-
| ^^^^^^^^^
22+
31 | let _: i32 = transmute(x);
23+
| ^^^^^^^^^
2424
|
2525
= note: source type: [T; 10] (size can vary because of T)
26-
= note: target type: isize (64 bits)
26+
= note: target type: i32 (32 bits)
2727

2828
error[E0512]: transmute called with types of different sizes
29-
--> $DIR/transmute-type-parameters.rs:35:20
29+
--> $DIR/transmute-type-parameters.rs:40:18
3030
|
31-
35 | let _: isize = transmute(x);
32-
| ^^^^^^^^^
31+
40 | let _: i32 = transmute(x);
32+
| ^^^^^^^^^
3333
|
3434
= note: source type: Bad<T> (size can vary because of T)
35-
= note: target type: isize (64 bits)
35+
= note: target type: i32 (32 bits)
3636

3737
error[E0512]: transmute called with types of different sizes
38-
--> $DIR/transmute-type-parameters.rs:45:20
38+
--> $DIR/transmute-type-parameters.rs:50:18
3939
|
40-
45 | let _: isize = transmute(x);
41-
| ^^^^^^^^^
40+
50 | let _: i32 = transmute(x);
41+
| ^^^^^^^^^
4242
|
4343
= note: source type: Worse<T> (size can vary because of T)
44-
= note: target type: isize (64 bits)
44+
= note: target type: i32 (32 bits)
4545

4646
error[E0512]: transmute called with types of different sizes
47-
--> $DIR/transmute-type-parameters.rs:50:20
47+
--> $DIR/transmute-type-parameters.rs:55:18
4848
|
49-
50 | let _: isize = transmute(x);
50-
| ^^^^^^^^^
49+
55 | let _: i32 = transmute(x);
50+
| ^^^^^^^^^
5151
|
5252
= note: source type: std::option::Option<T> (size can vary because of T)
53-
= note: target type: isize (64 bits)
53+
= note: target type: i32 (32 bits)
5454

5555
error: aborting due to previous error(s)
5656

0 commit comments

Comments
 (0)