Skip to content

Commit 18d1459

Browse files
committed
error -> warning
1 parent a5cc7c7 commit 18d1459

11 files changed

+213
-40
lines changed

src/test/compile-fail/issue-28625.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ struct ArrayPeano<T: Bar> {
1717
}
1818

1919
fn foo<T>(a: &ArrayPeano<T>) -> &[T] where T: Bar {
20-
unsafe { std::mem::transmute(a) } //~ ERROR transmute called with types of different sizes
20+
unsafe { std::mem::transmute(a) }
21+
//~^ WARN transmutation to a type with an unspecified layout
22+
//~| ERROR transmute called with types of different sizes
2123
}
2224

2325
impl Bar for () {

src/test/compile-fail/issue-32377.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ struct Bar<U: Foo> {
2121

2222
fn foo<U: Foo>(x: [usize; 2]) -> Bar<U> {
2323
unsafe { mem::transmute(x) }
24-
//~^ ERROR transmute called with types of different sizes
24+
//~^ WARN transmutation to a type with an unspecified layout
25+
//~| ERROR transmute called with types of different sizes
2526
}
2627

2728
fn main() {}

src/test/compile-fail/issue-35570.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ trait Trait2<'a> {
1919

2020
fn _ice(param: Box<for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
2121
let _e: (usize, usize) = unsafe{mem::transmute(param)};
22+
//~^ WARN transmutation to a type with an unspecified layout
23+
//~| WARN transmutation from a type with an unspecified layout
2224
}
2325

2426
trait Lifetime<'a> {

src/test/compile-fail/transmute-fat-pointers.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@
1515
use std::mem::transmute;
1616

1717
fn a<T, U: ?Sized>(x: &[T]) -> &U {
18-
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
18+
unsafe { transmute(x) }
19+
//~^ WARN transmutation to a type with an unspecified layout
20+
//~| WARN transmutation from a type with an unspecified layout
21+
//~| ERROR transmute called with types of different sizes
1922
}
2023

2124
fn b<T: ?Sized, U: ?Sized>(x: &T) -> &U {
22-
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
25+
unsafe { transmute(x) }
26+
//~^ WARN transmutation to a type with an unspecified layout
27+
//~| WARN transmutation from a type with an unspecified layout
28+
//~| ERROR transmute called with types of different sizes
2329
}
2430

2531
fn c<T, U>(x: &T) -> &U {
@@ -28,14 +34,20 @@ fn c<T, U>(x: &T) -> &U {
2834

2935
fn d<T, U>(x: &[T]) -> &[U] {
3036
unsafe { transmute(x) }
37+
//~^ WARN transmutation to a type with an unspecified layout
38+
//~| WARN transmutation from a type with an unspecified layout
3139
}
3240

3341
fn e<T: ?Sized, U>(x: &T) -> &U {
34-
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
42+
unsafe { transmute(x) }
43+
//~^ WARN transmutation from a type with an unspecified layout
44+
//~| ERROR transmute called with types of different sizes
3545
}
3646

3747
fn f<T, U: ?Sized>(x: &T) -> &U {
38-
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
48+
unsafe { transmute(x) }
49+
//~^ WARN transmutation to a type with an unspecified layout
50+
//~| ERROR transmute called with types of different sizes
3951
}
4052

4153
fn main() { }

src/test/compile-fail/transmute-impl.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ impl<T: ?Sized> Foo<T> {
2626

2727
fn n(x: &T) -> &isize {
2828
// Not OK here, because T : Sized is not in scope.
29-
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
29+
unsafe { transmute(x) }
30+
//~^ WARN transmutation from a type with an unspecified layout
31+
//~| ERROR transmute called with types of different sizes
3032
}
3133
}
3234

src/test/ui/transmute/main.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ unsafe fn sizes() {
3131
}
3232

3333
unsafe fn ptrs() {
34-
let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
34+
let x: u8 = transmute("test");
35+
//~^ WARN transmutation from a type with an unspecified layout
36+
//~| ERROR transmute called with types of different sizes
3537
}
3638

3739
union Foo { x: () }
3840
unsafe fn vary() {
39-
let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes
41+
let x: Foo = transmute(10);
42+
//~^ WARN transmutation to a type with an unspecified layout
43+
//~| ERROR transmute called with types of different sizes
4044
}
4145

4246
fn main() {}

src/test/ui/transmute/main.stderr

+23-4
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,43 @@ LL | let x: u8 = transmute(10u16); //~ ERROR transmute called with types of
1616
= note: source type: u16 (16 bits)
1717
= note: target type: u8 (8 bits)
1818

19+
warning[E0912]: transmutation from a type with an unspecified layout
20+
--> $DIR/main.rs:34:17
21+
|
22+
LL | let x: u8 = transmute("test");
23+
| ^^^^^^^^^
24+
|
25+
= note: &str has an unspecified layout
26+
= note: this will become a hard error in the future
27+
1928
error[E0512]: transmute called with types of different sizes
2029
--> $DIR/main.rs:34:17
2130
|
22-
LL | let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
31+
LL | let x: u8 = transmute("test");
2332
| ^^^^^^^^^
2433
|
2534
= note: source type: &str ($STR bits)
2635
= note: target type: u8 (8 bits)
2736

37+
warning[E0912]: transmutation to a type with an unspecified layout
38+
--> $DIR/main.rs:41:18
39+
|
40+
LL | let x: Foo = transmute(10);
41+
| ^^^^^^^^^
42+
|
43+
= note: Foo has an unspecified layout
44+
= note: this will become a hard error in the future
45+
2846
error[E0512]: transmute called with types of different sizes
29-
--> $DIR/main.rs:39:18
47+
--> $DIR/main.rs:41:18
3048
|
31-
LL | let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes
49+
LL | let x: Foo = transmute(10);
3250
| ^^^^^^^^^
3351
|
3452
= note: source type: i32 (32 bits)
3553
= note: target type: Foo (0 bits)
3654

3755
error: aborting due to 4 previous errors
3856

39-
For more information about this error, try `rustc --explain E0512`.
57+
Some errors occurred: E0512, E0912.
58+
For more information about an error, try `rustc --explain E0512`.

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

+18-9
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ use std::mem;
1212

1313
unsafe fn foo() -> (i8, *const (), Option<fn()>) {
1414
let i = mem::transmute(bar);
15-
//~^ ERROR transmute called with types of different sizes
15+
//~^ WARN transmutation from a type with an unspecified layout
16+
//~| ERROR transmute called with types of different sizes
1617

1718

1819
let p = mem::transmute(foo);
19-
//~^ ERROR can't transmute zero-sized type
20+
//~^ WARN transmutation from a type with an unspecified layout
21+
//~| ERROR can't transmute zero-sized type
2022

2123

2224
let of = mem::transmute(main);
23-
//~^ ERROR can't transmute zero-sized type
25+
//~^ WARN transmutation from a type with an unspecified layout
26+
//~| ERROR can't transmute zero-sized type
2427

2528

2629
(i, p, of)
@@ -29,15 +32,18 @@ unsafe fn foo() -> (i8, *const (), Option<fn()>) {
2932
unsafe fn bar() {
3033
// Error as usual if the resulting type is not pointer-sized.
3134
mem::transmute::<_, u8>(main);
32-
//~^ ERROR transmute called with types of different sizes
35+
//~^ WARN transmutation from a type with an unspecified layout
36+
//~| ERROR transmute called with types of different sizes
3337

3438

3539
mem::transmute::<_, *mut ()>(foo);
36-
//~^ ERROR can't transmute zero-sized type
40+
//~^ WARN transmutation from a type with an unspecified layout
41+
//~| ERROR can't transmute zero-sized type
3742

3843

3944
mem::transmute::<_, fn()>(bar);
40-
//~^ ERROR can't transmute zero-sized type
45+
//~^ WARN transmutation from a type with an unspecified layout
46+
//~| ERROR can't transmute zero-sized type
4147

4248

4349
// No error if a coercion would otherwise occur.
@@ -46,15 +52,18 @@ unsafe fn bar() {
4652

4753
unsafe fn baz() {
4854
mem::transmute::<_, *mut ()>(Some(foo));
49-
//~^ ERROR can't transmute zero-sized type
55+
//~^ WARN transmutation from a type with an unspecified layout
56+
//~| ERROR can't transmute zero-sized type
5057

5158

5259
mem::transmute::<_, fn()>(Some(bar));
53-
//~^ ERROR can't transmute zero-sized type
60+
//~^ WARN transmutation from a type with an unspecified layout
61+
//~| ERROR can't transmute zero-sized type
5462

5563

5664
mem::transmute::<_, Option<fn()>>(Some(baz));
57-
//~^ ERROR can't transmute zero-sized type
65+
//~^ WARN transmutation from a type with an unspecified layout
66+
//~| ERROR can't transmute zero-sized type
5867

5968

6069
// No error if a coercion would otherwise occur.

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

+90-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
warning[E0912]: transmutation from a type with an unspecified layout
2+
--> $DIR/transmute-from-fn-item-types-error.rs:14:13
3+
|
4+
LL | let i = mem::transmute(bar);
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: unsafe fn() {bar} has an unspecified layout
8+
= note: this will become a hard error in the future
9+
110
error[E0512]: transmute called with types of different sizes
211
--> $DIR/transmute-from-fn-item-types-error.rs:14:13
312
|
@@ -7,8 +16,17 @@ LL | let i = mem::transmute(bar);
716
= note: source type: unsafe fn() {bar} (0 bits)
817
= note: target type: i8 (8 bits)
918

19+
warning[E0912]: transmutation from a type with an unspecified layout
20+
--> $DIR/transmute-from-fn-item-types-error.rs:19:13
21+
|
22+
LL | let p = mem::transmute(foo);
23+
| ^^^^^^^^^^^^^^
24+
|
25+
= note: unsafe fn() -> (i8, *const (), std::option::Option<fn()>) {foo} has an unspecified layout
26+
= note: this will become a hard error in the future
27+
1028
error[E0591]: can't transmute zero-sized type
11-
--> $DIR/transmute-from-fn-item-types-error.rs:18:13
29+
--> $DIR/transmute-from-fn-item-types-error.rs:19:13
1230
|
1331
LL | let p = mem::transmute(foo);
1432
| ^^^^^^^^^^^^^^
@@ -17,8 +35,17 @@ LL | let p = mem::transmute(foo);
1735
= note: target type: *const ()
1836
= help: cast with `as` to a pointer instead
1937

38+
warning[E0912]: transmutation from a type with an unspecified layout
39+
--> $DIR/transmute-from-fn-item-types-error.rs:24:14
40+
|
41+
LL | let of = mem::transmute(main);
42+
| ^^^^^^^^^^^^^^
43+
|
44+
= note: fn() {main} has an unspecified layout
45+
= note: this will become a hard error in the future
46+
2047
error[E0591]: can't transmute zero-sized type
21-
--> $DIR/transmute-from-fn-item-types-error.rs:22:14
48+
--> $DIR/transmute-from-fn-item-types-error.rs:24:14
2249
|
2350
LL | let of = mem::transmute(main);
2451
| ^^^^^^^^^^^^^^
@@ -27,17 +54,35 @@ LL | let of = mem::transmute(main);
2754
= note: target type: std::option::Option<fn()>
2855
= help: cast with `as` to a pointer instead
2956

57+
warning[E0912]: transmutation from a type with an unspecified layout
58+
--> $DIR/transmute-from-fn-item-types-error.rs:34:5
59+
|
60+
LL | mem::transmute::<_, u8>(main);
61+
| ^^^^^^^^^^^^^^^^^^^^^^^
62+
|
63+
= note: fn() {main} has an unspecified layout
64+
= note: this will become a hard error in the future
65+
3066
error[E0512]: transmute called with types of different sizes
31-
--> $DIR/transmute-from-fn-item-types-error.rs:31:5
67+
--> $DIR/transmute-from-fn-item-types-error.rs:34:5
3268
|
3369
LL | mem::transmute::<_, u8>(main);
3470
| ^^^^^^^^^^^^^^^^^^^^^^^
3571
|
3672
= note: source type: fn() {main} (0 bits)
3773
= note: target type: u8 (8 bits)
3874

75+
warning[E0912]: transmutation from a type with an unspecified layout
76+
--> $DIR/transmute-from-fn-item-types-error.rs:39:5
77+
|
78+
LL | mem::transmute::<_, *mut ()>(foo);
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
|
81+
= note: unsafe fn() -> (i8, *const (), std::option::Option<fn()>) {foo} has an unspecified layout
82+
= note: this will become a hard error in the future
83+
3984
error[E0591]: can't transmute zero-sized type
40-
--> $DIR/transmute-from-fn-item-types-error.rs:35:5
85+
--> $DIR/transmute-from-fn-item-types-error.rs:39:5
4186
|
4287
LL | mem::transmute::<_, *mut ()>(foo);
4388
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -46,8 +91,17 @@ LL | mem::transmute::<_, *mut ()>(foo);
4691
= note: target type: *mut ()
4792
= help: cast with `as` to a pointer instead
4893

94+
warning[E0912]: transmutation from a type with an unspecified layout
95+
--> $DIR/transmute-from-fn-item-types-error.rs:44:5
96+
|
97+
LL | mem::transmute::<_, fn()>(bar);
98+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
99+
|
100+
= note: unsafe fn() {bar} has an unspecified layout
101+
= note: this will become a hard error in the future
102+
49103
error[E0591]: can't transmute zero-sized type
50-
--> $DIR/transmute-from-fn-item-types-error.rs:39:5
104+
--> $DIR/transmute-from-fn-item-types-error.rs:44:5
51105
|
52106
LL | mem::transmute::<_, fn()>(bar);
53107
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -56,8 +110,17 @@ LL | mem::transmute::<_, fn()>(bar);
56110
= note: target type: fn()
57111
= help: cast with `as` to a pointer instead
58112

113+
warning[E0912]: transmutation from a type with an unspecified layout
114+
--> $DIR/transmute-from-fn-item-types-error.rs:54:5
115+
|
116+
LL | mem::transmute::<_, *mut ()>(Some(foo));
117+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
118+
|
119+
= note: std::option::Option<unsafe fn() -> (i8, *const (), std::option::Option<fn()>) {foo}> has an unspecified layout
120+
= note: this will become a hard error in the future
121+
59122
error[E0591]: can't transmute zero-sized type
60-
--> $DIR/transmute-from-fn-item-types-error.rs:48:5
123+
--> $DIR/transmute-from-fn-item-types-error.rs:54:5
61124
|
62125
LL | mem::transmute::<_, *mut ()>(Some(foo));
63126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,8 +129,17 @@ LL | mem::transmute::<_, *mut ()>(Some(foo));
66129
= note: target type: *mut ()
67130
= help: cast with `as` to a pointer instead
68131

132+
warning[E0912]: transmutation from a type with an unspecified layout
133+
--> $DIR/transmute-from-fn-item-types-error.rs:59:5
134+
|
135+
LL | mem::transmute::<_, fn()>(Some(bar));
136+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
137+
|
138+
= note: std::option::Option<unsafe fn() {bar}> has an unspecified layout
139+
= note: this will become a hard error in the future
140+
69141
error[E0591]: can't transmute zero-sized type
70-
--> $DIR/transmute-from-fn-item-types-error.rs:52:5
142+
--> $DIR/transmute-from-fn-item-types-error.rs:59:5
71143
|
72144
LL | mem::transmute::<_, fn()>(Some(bar));
73145
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -76,8 +148,17 @@ LL | mem::transmute::<_, fn()>(Some(bar));
76148
= note: target type: fn()
77149
= help: cast with `as` to a pointer instead
78150

151+
warning[E0912]: transmutation from a type with an unspecified layout
152+
--> $DIR/transmute-from-fn-item-types-error.rs:64:5
153+
|
154+
LL | mem::transmute::<_, Option<fn()>>(Some(baz));
155+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156+
|
157+
= note: std::option::Option<unsafe fn() {baz}> has an unspecified layout
158+
= note: this will become a hard error in the future
159+
79160
error[E0591]: can't transmute zero-sized type
80-
--> $DIR/transmute-from-fn-item-types-error.rs:56:5
161+
--> $DIR/transmute-from-fn-item-types-error.rs:64:5
81162
|
82163
LL | mem::transmute::<_, Option<fn()>>(Some(baz));
83164
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -88,5 +169,5 @@ LL | mem::transmute::<_, Option<fn()>>(Some(baz));
88169

89170
error: aborting due to 9 previous errors
90171

91-
Some errors occurred: E0512, E0591.
172+
Some errors occurred: E0512, E0591, E0912.
92173
For more information about an error, try `rustc --explain E0512`.

0 commit comments

Comments
 (0)