Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80f0651

Browse files
committedJun 5, 2017
Auto merge of #42445 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 4 pull requests - Successful merges: #42304, #42415, #42429, #42438 - Failed merges:
2 parents d015610 + fd48c3a commit 80f0651

24 files changed

+298
-56
lines changed
 

‎src/bootstrap/compile.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ pub fn rustc(build: &Build, target: &str, compiler: &Compiler) {
276276
if build.is_rust_llvm(target) {
277277
cargo.env("LLVM_RUSTLLVM", "1");
278278
}
279+
if let Some(ref cfg_file) = build.flags.config {
280+
let cfg_path = t!(PathBuf::from(cfg_file).canonicalize());
281+
cargo.env("CFG_LLVM_TOML", cfg_path.into_os_string());
282+
}
279283
cargo.env("LLVM_CONFIG", build.llvm_config(target));
280284
let target_config = build.config.target_config.get(target);
281285
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {

‎src/libcore/marker.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub trait Unsize<T: ?Sized> {
205205
/// but not `Copy`.
206206
///
207207
/// [`Clone`] is a supertrait of `Copy`, so everything which is `Copy` must also implement
208-
/// [`Clone`]. If a type is `Copy` then its [`Clone`] implementation need only return `*self`
208+
/// [`Clone`]. If a type is `Copy` then its [`Clone`] implementation only needs to return `*self`
209209
/// (see the example above).
210210
///
211211
/// ## When can my type be `Copy`?

‎src/librustc/diagnostics.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ fn takes_u8(_: u8) {}
16311631
16321632
fn main() {
16331633
unsafe { takes_u8(::std::mem::transmute(0u16)); }
1634-
// error: transmute called with differently sized types
1634+
// error: transmute called with types of different sizes
16351635
}
16361636
```
16371637

‎src/librustc/middle/intrinsicck.rs‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,16 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
8686
// Special-case transmutting from `typeof(function)` and
8787
// `Option<typeof(function)>` to present a clearer error.
8888
let from = unpack_option_like(self.tcx.global_tcx(), from);
89-
match (&from.sty, sk_to) {
90-
(&ty::TyFnDef(..), SizeSkeleton::Known(size_to))
91-
if size_to == Pointer.size(self.tcx) => {
89+
if let (&ty::TyFnDef(..), SizeSkeleton::Known(size_to)) = (&from.sty, sk_to) {
90+
if size_to == Pointer.size(self.tcx) {
9291
struct_span_err!(self.tcx.sess, span, E0591,
93-
"`{}` is zero-sized and can't be transmuted to `{}`",
94-
from, to)
95-
.span_note(span, "cast with `as` to a pointer instead")
92+
"can't transmute zero-sized type")
93+
.note(&format!("source type: {}", from))
94+
.note(&format!("target type: {}", to))
95+
.help("cast with `as` to a pointer instead")
9696
.emit();
9797
return;
9898
}
99-
_ => {}
10099
}
101100
}
102101

@@ -111,7 +110,7 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
111110
}
112111
Err(LayoutError::Unknown(bad)) => {
113112
if bad == ty {
114-
format!("size can vary")
113+
format!("this type's size can vary")
115114
} else {
116115
format!("size can vary because of {}", bad)
117116
}
@@ -121,14 +120,9 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
121120
};
122121

123122
struct_span_err!(self.tcx.sess, span, E0512,
124-
"transmute called with differently sized types: \
125-
{} ({}) to {} ({})",
126-
from, skeleton_string(from, sk_from),
127-
to, skeleton_string(to, sk_to))
128-
.span_label(span,
129-
format!("transmuting between {} and {}",
130-
skeleton_string(from, sk_from),
131-
skeleton_string(to, sk_to)))
123+
"transmute called with types of different sizes")
124+
.note(&format!("source type: {} ({})", from, skeleton_string(from, sk_from)))
125+
.note(&format!("target type: {} ({})", to, skeleton_string(to, sk_to)))
132126
.emit();
133127
}
134128
}

‎src/librustc/middle/resolve_lifetime.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13631363
m.push_str(&(if n == 1 {
13641364
help_name
13651365
} else {
1366-
format!("one of {}'s {} elided {}lifetimes", help_name, n,
1366+
format!("one of {}'s {} {}lifetimes", help_name, n,
13671367
if have_bound_regions { "free " } else { "" } )
13681368
})[..]);
13691369

‎src/librustc_llvm/build.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ fn main() {
6161

6262
println!("cargo:rerun-if-changed={}", llvm_config.display());
6363

64+
if let Some(cfg_toml) = env::var_os("CFG_LLVM_TOML") {
65+
let cfg_path = PathBuf::from(cfg_toml);
66+
println!("cargo:rerun-if-changed={}", cfg_path.display());
67+
}
68+
6469
// Test whether we're cross-compiling LLVM. This is a pretty rare case
6570
// currently where we're producing an LLVM for a different platform than
6671
// what this build script is currently running on.

‎src/test/compile-fail/E0512.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ fn takes_u8(_: u8) {}
1212

1313
fn main() {
1414
unsafe { takes_u8(::std::mem::transmute(0u16)); } //~ ERROR E0512
15-
//~| transmuting between 16 bits and 8 bits
1615
}

‎src/test/compile-fail/issue-21174.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait Trait<'a> {
1515

1616
fn foo<'a, T: Trait<'a>>(value: T::A) {
1717
let new: T::B = unsafe { std::mem::transmute(value) };
18-
//~^ ERROR: transmute called with differently sized types
18+
//~^ ERROR: transmute called with types of different sizes
1919
}
2020

2121
fn main() { }

‎src/test/compile-fail/issue-26638.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
fn parse_type(iter: Box<Iterator<Item=&str>+'static>) -> &str { iter.next() }
1212
//~^ ERROR missing lifetime specifier [E0106]
13-
//~^^ HELP 2 elided lifetimes
13+
//~^^ HELP 2 lifetimes
1414

1515
fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
1616
//~^ ERROR missing lifetime specifier [E0106]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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 differently sized types
20+
unsafe { std::mem::transmute(a) } //~ ERROR transmute called with types of different sizes
2121
}
2222

2323
impl Bar for () {

‎src/test/compile-fail/issue-30255.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ struct S<'a> {
1717

1818
fn f(a: &S, b: i32) -> &i32 {
1919
//~^ ERROR missing lifetime specifier [E0106]
20-
//~^^ HELP does not say which one of `a`'s 2 elided lifetimes it is borrowed from
20+
//~^^ HELP does not say which one of `a`'s 2 lifetimes it is borrowed from
2121
panic!();
2222
}
2323

2424
fn g(a: &S, b: bool, c: &i32) -> &i32 {
2525
//~^ ERROR missing lifetime specifier [E0106]
26-
//~^^ HELP does not say whether it is borrowed from one of `a`'s 2 elided lifetimes or `c`
26+
//~^^ HELP does not say whether it is borrowed from one of `a`'s 2 lifetimes or `c`
2727
panic!();
2828
}
2929

3030
fn h(a: &bool, b: bool, c: &S, d: &i32) -> &i32 {
3131
//~^ ERROR missing lifetime specifier [E0106]
32-
//~^^ HELP does not say whether it is borrowed from `a`, one of `c`'s 2 elided lifetimes, or `d`
32+
//~^^ HELP does not say whether it is borrowed from `a`, one of `c`'s 2 lifetimes, or `d`
3333
panic!();
3434
}
3535

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ 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 differently sized types
24+
//~^ ERROR transmute called with types of different sizes
2525
}
2626

2727
fn main() {}

‎src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct Foo<'a> {
2828
// Lifetime annotation needed because we have two lifetimes: one as a parameter
2929
// and one on the reference.
3030
fn h(_x: &Foo) -> &isize { //~ ERROR missing lifetime specifier
31-
//~^ HELP the signature does not say which one of `_x`'s 2 elided lifetimes it is borrowed from
31+
//~^ HELP the signature does not say which one of `_x`'s 2 lifetimes it is borrowed from
3232
panic!()
3333
}
3434

‎src/test/compile-fail/packed-struct-generic-transmute.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// the error points to the start of the file, not the line with the
1414
// transmute
1515

16-
// error-pattern: transmute called with differently sized types
16+
// error-pattern: transmute called with types of different sizes
1717

1818
use std::mem;
1919

‎src/test/compile-fail/packed-struct-transmute.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// the error points to the start of the file, not the line with the
1414
// transmute
1515

16-
// error-pattern: transmute called with differently sized types
16+
// error-pattern: transmute called with types of different sizes
1717

1818
use std::mem;
1919

‎src/test/compile-fail/transmute-different-sizes.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ use std::mem::transmute;
1717

1818
unsafe fn f() {
1919
let _: i8 = transmute(16i16);
20-
//~^ ERROR transmute called with differently sized types
20+
//~^ ERROR transmute called with types of different sizes
2121
}
2222

2323
unsafe fn g<T>(x: &T) {
2424
let _: i8 = transmute(x);
25-
//~^ ERROR transmute called with differently sized types
25+
//~^ ERROR transmute called with types of different sizes
2626
}
2727

2828
trait Specializable { type Output; }
@@ -33,7 +33,7 @@ impl<T> Specializable for T {
3333

3434
unsafe fn specializable<T>(x: u16) -> <T as Specializable>::Output {
3535
transmute(x)
36-
//~^ ERROR transmute called with differently sized types
36+
//~^ ERROR transmute called with types of different sizes
3737
}
3838

3939
fn main() {}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
use std::mem::transmute;
1616

1717
fn a<T, U: ?Sized>(x: &[T]) -> &U {
18-
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
18+
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
1919
}
2020

2121
fn b<T: ?Sized, U: ?Sized>(x: &T) -> &U {
22-
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
22+
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
2323
}
2424

2525
fn c<T, U>(x: &T) -> &U {
@@ -31,11 +31,11 @@ fn d<T, U>(x: &[T]) -> &[U] {
3131
}
3232

3333
fn e<T: ?Sized, U>(x: &T) -> &U {
34-
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
34+
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
3535
}
3636

3737
fn f<T, U: ?Sized>(x: &T) -> &U {
38-
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
38+
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
3939
}
4040

4141
fn main() { }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ 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 differently sized types
29+
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
3030
}
3131
}
3232

‎src/test/ui/transmute/main.rs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(untagged_unions)]
11+
use std::mem::transmute;
12+
13+
pub trait TypeConstructor<'a> {
14+
type T;
15+
}
16+
17+
unsafe fn transmute_lifetime<'a, 'b, C>(x: <C as TypeConstructor<'a>>::T)
18+
-> <C as TypeConstructor<'b>>::T
19+
where for<'z> C: TypeConstructor<'z> {
20+
transmute(x) //~ ERROR transmute called with types of different sizes
21+
}
22+
23+
unsafe fn sizes() {
24+
let x: u8 = transmute(10u16); //~ ERROR transmute called with types of different sizes
25+
}
26+
27+
unsafe fn ptrs() {
28+
let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
29+
}
30+
31+
union Foo { x: () }
32+
unsafe fn vary() {
33+
let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes
34+
}
35+
36+
fn main() {}

‎src/test/ui/transmute/main.stderr‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error[E0512]: transmute called with types of different sizes
2+
--> $DIR/main.rs:20:5
3+
|
4+
20 | transmute(x) //~ ERROR transmute called with types of different sizes
5+
| ^^^^^^^^^
6+
|
7+
= note: source type: <C as TypeConstructor<'a>>::T (size can vary because of <C as TypeConstructor>::T)
8+
= note: target type: <C as TypeConstructor<'b>>::T (size can vary because of <C as TypeConstructor>::T)
9+
10+
error[E0512]: transmute called with types of different sizes
11+
--> $DIR/main.rs:24:17
12+
|
13+
24 | let x: u8 = transmute(10u16); //~ ERROR transmute called with types of different sizes
14+
| ^^^^^^^^^
15+
|
16+
= note: source type: u16 (16 bits)
17+
= note: target type: u8 (8 bits)
18+
19+
error[E0512]: transmute called with types of different sizes
20+
--> $DIR/main.rs:28:17
21+
|
22+
28 | let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
23+
| ^^^^^^^^^
24+
|
25+
= note: source type: &str (128 bits)
26+
= note: target type: u8 (8 bits)
27+
28+
error[E0512]: transmute called with types of different sizes
29+
--> $DIR/main.rs:33:18
30+
|
31+
33 | let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes
32+
| ^^^^^^^^^
33+
|
34+
= note: source type: i32 (32 bits)
35+
= note: target type: Foo (0 bits)
36+
37+
error: aborting due to previous error(s)
38+

‎src/test/compile-fail/transmute-from-fn-item-types-error.rs‎ renamed to ‎src/test/ui/transmute/transmute-from-fn-item-types-error.rs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-x86 fn() has different sizes dependent on platform
12+
1113
use std::mem;
1214

13-
unsafe fn foo() -> (isize, *const (), Option<fn()>) {
15+
unsafe fn foo() -> (i32, *const (), Option<fn()>) {
1416
let i = mem::transmute(bar);
1517
//~^ ERROR is zero-sized and can't be transmuted
1618
//~^^ NOTE cast with `as` to a pointer instead
@@ -29,8 +31,8 @@ unsafe fn foo() -> (isize, *const (), Option<fn()>) {
2931
unsafe fn bar() {
3032
// Error as usual if the resulting type is not pointer-sized.
3133
mem::transmute::<_, u8>(main);
32-
//~^ ERROR transmute called with differently sized types
33-
//~^^ NOTE transmuting between 0 bits and 8 bits
34+
//~^ ERROR transmute called with types of different sizes
35+
//~^^ NOTE transmuting between fn() {main} and u8
3436

3537
mem::transmute::<_, *mut ()>(foo);
3638
//~^ ERROR is zero-sized and can't be transmuted
@@ -41,7 +43,7 @@ unsafe fn bar() {
4143
//~^^ NOTE cast with `as` to a pointer instead
4244

4345
// No error if a coercion would otherwise occur.
44-
mem::transmute::<fn(), usize>(main);
46+
mem::transmute::<fn(), u32>(main);
4547
}
4648

4749
unsafe fn baz() {
@@ -58,7 +60,7 @@ unsafe fn baz() {
5860
//~^^ NOTE cast with `as` to a pointer instead
5961

6062
// No error if a coercion would otherwise occur.
61-
mem::transmute::<Option<fn()>, usize>(Some(main));
63+
mem::transmute::<Option<fn()>, u32>(Some(main));
6264
}
6365

6466
fn main() {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
error[E0512]: transmute called with types of different sizes
2+
--> $DIR/transmute-from-fn-item-types-error.rs:16:13
3+
|
4+
16 | let i = mem::transmute(bar);
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: source type: unsafe fn() {bar} (0 bits)
8+
= note: target type: i32 (32 bits)
9+
10+
error[E0591]: can't transmute zero-sized type
11+
--> $DIR/transmute-from-fn-item-types-error.rs:20:13
12+
|
13+
20 | let p = mem::transmute(foo);
14+
| ^^^^^^^^^^^^^^
15+
|
16+
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
17+
= note: target type: *const ()
18+
= help: cast with `as` to a pointer instead
19+
20+
error[E0591]: can't transmute zero-sized type
21+
--> $DIR/transmute-from-fn-item-types-error.rs:24:14
22+
|
23+
24 | let of = mem::transmute(main);
24+
| ^^^^^^^^^^^^^^
25+
|
26+
= note: source type: fn() {main}
27+
= note: target type: std::option::Option<fn()>
28+
= help: cast with `as` to a pointer instead
29+
30+
error[E0512]: transmute called with types of different sizes
31+
--> $DIR/transmute-from-fn-item-types-error.rs:33:5
32+
|
33+
33 | mem::transmute::<_, u8>(main);
34+
| ^^^^^^^^^^^^^^^^^^^^^^^
35+
|
36+
= note: source type: fn() {main} (0 bits)
37+
= note: target type: u8 (8 bits)
38+
39+
error[E0591]: can't transmute zero-sized type
40+
--> $DIR/transmute-from-fn-item-types-error.rs:37:5
41+
|
42+
37 | mem::transmute::<_, *mut ()>(foo);
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
|
45+
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
46+
= note: target type: *mut ()
47+
= help: cast with `as` to a pointer instead
48+
49+
error[E0591]: can't transmute zero-sized type
50+
--> $DIR/transmute-from-fn-item-types-error.rs:41:5
51+
|
52+
41 | mem::transmute::<_, fn()>(bar);
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
54+
|
55+
= note: source type: unsafe fn() {bar}
56+
= note: target type: fn()
57+
= help: cast with `as` to a pointer instead
58+
59+
error[E0512]: transmute called with types of different sizes
60+
--> $DIR/transmute-from-fn-item-types-error.rs:46:5
61+
|
62+
46 | mem::transmute::<fn(), u32>(main);
63+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
64+
|
65+
= note: source type: fn() (64 bits)
66+
= note: target type: u32 (32 bits)
67+
68+
error[E0591]: can't transmute zero-sized type
69+
--> $DIR/transmute-from-fn-item-types-error.rs:50:5
70+
|
71+
50 | mem::transmute::<_, *mut ()>(Some(foo));
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73+
|
74+
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
75+
= note: target type: *mut ()
76+
= help: cast with `as` to a pointer instead
77+
78+
error[E0591]: can't transmute zero-sized type
79+
--> $DIR/transmute-from-fn-item-types-error.rs:54:5
80+
|
81+
54 | mem::transmute::<_, fn()>(Some(bar));
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
83+
|
84+
= note: source type: unsafe fn() {bar}
85+
= note: target type: fn()
86+
= help: cast with `as` to a pointer instead
87+
88+
error[E0591]: can't transmute zero-sized type
89+
--> $DIR/transmute-from-fn-item-types-error.rs:58:5
90+
|
91+
58 | mem::transmute::<_, Option<fn()>>(Some(baz));
92+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
93+
|
94+
= note: source type: unsafe fn() {baz}
95+
= note: target type: std::option::Option<fn()>
96+
= help: cast with `as` to a pointer instead
97+
98+
error[E0512]: transmute called with types of different sizes
99+
--> $DIR/transmute-from-fn-item-types-error.rs:63:5
100+
|
101+
63 | 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+
107+
error: aborting due to previous error(s)
108+

‎src/test/compile-fail/transmute-type-parameters.rs‎ renamed to ‎src/test/ui/transmute/transmute-type-parameters.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@
1313
use std::mem::transmute;
1414

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

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
20+
unsafe fn g<T>(x: (T, i32)) {
21+
let _: i32 = transmute(x);
22+
//~^ ERROR differently sized types: (T, i32) (size can vary because of T) to i32
2323
}
2424

2525
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
26+
let _: i32 = transmute(x);
27+
//~^ ERROR differently sized types: [T; 10] (size can vary because of T) to i32
2828
}
2929

3030
struct Bad<T> {
3131
f: T,
3232
}
3333

3434
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
35+
let _: i32 = transmute(x);
36+
//~^ ERROR differently sized types: Bad<T> (size can vary because of T) to i32
3737
}
3838

3939
enum Worse<T> {
@@ -42,13 +42,13 @@ enum Worse<T> {
4242
}
4343

4444
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
45+
let _: i32 = transmute(x);
46+
//~^ ERROR differently sized types: Worse<T> (size can vary because of T) to i32
4747
}
4848

4949
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
50+
let _: i32 = transmute(x);
51+
//~^ ERROR differently sized types: std::option::Option<T> (size can vary because of T) to i32
5252
}
5353

5454
fn main() {}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
error[E0512]: transmute called with types of different sizes
2+
--> $DIR/transmute-type-parameters.rs:16:18
3+
|
4+
16 | let _: i32 = transmute(x);
5+
| ^^^^^^^^^
6+
|
7+
= note: source type: T (this type's size can vary)
8+
= note: target type: i32 (32 bits)
9+
10+
error[E0512]: transmute called with types of different sizes
11+
--> $DIR/transmute-type-parameters.rs:21:18
12+
|
13+
21 | let _: i32 = transmute(x);
14+
| ^^^^^^^^^
15+
|
16+
= note: source type: (T, i32) (size can vary because of T)
17+
= note: target type: i32 (32 bits)
18+
19+
error[E0512]: transmute called with types of different sizes
20+
--> $DIR/transmute-type-parameters.rs:26:18
21+
|
22+
26 | let _: i32 = transmute(x);
23+
| ^^^^^^^^^
24+
|
25+
= note: source type: [T; 10] (size can vary because of T)
26+
= note: target type: i32 (32 bits)
27+
28+
error[E0512]: transmute called with types of different sizes
29+
--> $DIR/transmute-type-parameters.rs:35:18
30+
|
31+
35 | let _: i32 = transmute(x);
32+
| ^^^^^^^^^
33+
|
34+
= note: source type: Bad<T> (size can vary because of T)
35+
= note: target type: i32 (32 bits)
36+
37+
error[E0512]: transmute called with types of different sizes
38+
--> $DIR/transmute-type-parameters.rs:45:18
39+
|
40+
45 | let _: i32 = transmute(x);
41+
| ^^^^^^^^^
42+
|
43+
= note: source type: Worse<T> (size can vary because of T)
44+
= note: target type: i32 (32 bits)
45+
46+
error[E0512]: transmute called with types of different sizes
47+
--> $DIR/transmute-type-parameters.rs:50:18
48+
|
49+
50 | let _: i32 = transmute(x);
50+
| ^^^^^^^^^
51+
|
52+
= note: source type: std::option::Option<T> (size can vary because of T)
53+
= note: target type: i32 (32 bits)
54+
55+
error: aborting due to previous error(s)
56+

0 commit comments

Comments
 (0)
Please sign in to comment.