diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 9946c93913fe7..9a07e8a8b1091 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -276,6 +276,10 @@ pub fn rustc(build: &Build, target: &str, compiler: &Compiler) { if build.is_rust_llvm(target) { cargo.env("LLVM_RUSTLLVM", "1"); } + if let Some(ref cfg_file) = build.flags.config { + let cfg_path = t!(PathBuf::from(cfg_file).canonicalize()); + cargo.env("CFG_LLVM_TOML", cfg_path.into_os_string()); + } cargo.env("LLVM_CONFIG", build.llvm_config(target)); let target_config = build.config.target_config.get(target); if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 6602fccd58982..05df84708e05d 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -205,7 +205,7 @@ pub trait Unsize { /// but not `Copy`. /// /// [`Clone`] is a supertrait of `Copy`, so everything which is `Copy` must also implement -/// [`Clone`]. If a type is `Copy` then its [`Clone`] implementation need only return `*self` +/// [`Clone`]. If a type is `Copy` then its [`Clone`] implementation only needs to return `*self` /// (see the example above). /// /// ## When can my type be `Copy`? diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 2beb40d6b2f1a..4cd25f49c7884 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1631,7 +1631,7 @@ fn takes_u8(_: u8) {} fn main() { unsafe { takes_u8(::std::mem::transmute(0u16)); } - // error: transmute called with differently sized types + // error: transmute called with types of different sizes } ``` diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 57815b7f0b690..f180ae53b8ae1 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -86,17 +86,16 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> { // Special-case transmutting from `typeof(function)` and // `Option` to present a clearer error. let from = unpack_option_like(self.tcx.global_tcx(), from); - match (&from.sty, sk_to) { - (&ty::TyFnDef(..), SizeSkeleton::Known(size_to)) - if size_to == Pointer.size(self.tcx) => { + if let (&ty::TyFnDef(..), SizeSkeleton::Known(size_to)) = (&from.sty, sk_to) { + if size_to == Pointer.size(self.tcx) { struct_span_err!(self.tcx.sess, span, E0591, - "`{}` is zero-sized and can't be transmuted to `{}`", - from, to) - .span_note(span, "cast with `as` to a pointer instead") + "can't transmute zero-sized type") + .note(&format!("source type: {}", from)) + .note(&format!("target type: {}", to)) + .help("cast with `as` to a pointer instead") .emit(); return; } - _ => {} } } @@ -111,7 +110,7 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> { } Err(LayoutError::Unknown(bad)) => { if bad == ty { - format!("size can vary") + format!("this type's size can vary") } else { format!("size can vary because of {}", bad) } @@ -121,14 +120,9 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> { }; struct_span_err!(self.tcx.sess, span, E0512, - "transmute called with differently sized types: \ - {} ({}) to {} ({})", - from, skeleton_string(from, sk_from), - to, skeleton_string(to, sk_to)) - .span_label(span, - format!("transmuting between {} and {}", - skeleton_string(from, sk_from), - skeleton_string(to, sk_to))) + "transmute called with types of different sizes") + .note(&format!("source type: {} ({})", from, skeleton_string(from, sk_from))) + .note(&format!("target type: {} ({})", to, skeleton_string(to, sk_to))) .emit(); } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 1a07423bcbc0f..ce5d58f5800c7 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1363,7 +1363,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { m.push_str(&(if n == 1 { help_name } else { - format!("one of {}'s {} elided {}lifetimes", help_name, n, + format!("one of {}'s {} {}lifetimes", help_name, n, if have_bound_regions { "free " } else { "" } ) })[..]); diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index ba568857959f8..bdfc0a2fe855c 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -61,6 +61,11 @@ fn main() { println!("cargo:rerun-if-changed={}", llvm_config.display()); + if let Some(cfg_toml) = env::var_os("CFG_LLVM_TOML") { + let cfg_path = PathBuf::from(cfg_toml); + println!("cargo:rerun-if-changed={}", cfg_path.display()); + } + // Test whether we're cross-compiling LLVM. This is a pretty rare case // currently where we're producing an LLVM for a different platform than // what this build script is currently running on. diff --git a/src/test/compile-fail/E0512.rs b/src/test/compile-fail/E0512.rs index 2b89873ee45ff..25f9627164131 100644 --- a/src/test/compile-fail/E0512.rs +++ b/src/test/compile-fail/E0512.rs @@ -12,5 +12,4 @@ fn takes_u8(_: u8) {} fn main() { unsafe { takes_u8(::std::mem::transmute(0u16)); } //~ ERROR E0512 - //~| transmuting between 16 bits and 8 bits } diff --git a/src/test/compile-fail/issue-21174.rs b/src/test/compile-fail/issue-21174.rs index c92a404b71a6f..9d9b7e4804354 100644 --- a/src/test/compile-fail/issue-21174.rs +++ b/src/test/compile-fail/issue-21174.rs @@ -15,7 +15,7 @@ trait Trait<'a> { fn foo<'a, T: Trait<'a>>(value: T::A) { let new: T::B = unsafe { std::mem::transmute(value) }; -//~^ ERROR: transmute called with differently sized types +//~^ ERROR: transmute called with types of different sizes } fn main() { } diff --git a/src/test/compile-fail/issue-26638.rs b/src/test/compile-fail/issue-26638.rs index f918f0aed7a10..9b8c7b250763e 100644 --- a/src/test/compile-fail/issue-26638.rs +++ b/src/test/compile-fail/issue-26638.rs @@ -10,7 +10,7 @@ fn parse_type(iter: Box+'static>) -> &str { iter.next() } //~^ ERROR missing lifetime specifier [E0106] -//~^^ HELP 2 elided lifetimes +//~^^ HELP 2 lifetimes fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() } //~^ ERROR missing lifetime specifier [E0106] diff --git a/src/test/compile-fail/issue-28625.rs b/src/test/compile-fail/issue-28625.rs index c332e4ea45973..dc9155ed66c6e 100644 --- a/src/test/compile-fail/issue-28625.rs +++ b/src/test/compile-fail/issue-28625.rs @@ -17,7 +17,7 @@ struct ArrayPeano { } fn foo(a: &ArrayPeano) -> &[T] where T: Bar { - unsafe { std::mem::transmute(a) } //~ ERROR transmute called with differently sized types + unsafe { std::mem::transmute(a) } //~ ERROR transmute called with types of different sizes } impl Bar for () { diff --git a/src/test/compile-fail/issue-30255.rs b/src/test/compile-fail/issue-30255.rs index 1daa6a61f777c..e3f55ae51e8b6 100644 --- a/src/test/compile-fail/issue-30255.rs +++ b/src/test/compile-fail/issue-30255.rs @@ -17,19 +17,19 @@ struct S<'a> { fn f(a: &S, b: i32) -> &i32 { //~^ ERROR missing lifetime specifier [E0106] -//~^^ HELP does not say which one of `a`'s 2 elided lifetimes it is borrowed from +//~^^ HELP does not say which one of `a`'s 2 lifetimes it is borrowed from panic!(); } fn g(a: &S, b: bool, c: &i32) -> &i32 { //~^ ERROR missing lifetime specifier [E0106] -//~^^ HELP does not say whether it is borrowed from one of `a`'s 2 elided lifetimes or `c` +//~^^ HELP does not say whether it is borrowed from one of `a`'s 2 lifetimes or `c` panic!(); } fn h(a: &bool, b: bool, c: &S, d: &i32) -> &i32 { //~^ ERROR missing lifetime specifier [E0106] -//~^^ HELP does not say whether it is borrowed from `a`, one of `c`'s 2 elided lifetimes, or `d` +//~^^ HELP does not say whether it is borrowed from `a`, one of `c`'s 2 lifetimes, or `d` panic!(); } diff --git a/src/test/compile-fail/issue-32377.rs b/src/test/compile-fail/issue-32377.rs index 6e8126348da69..5091ba4ee1aa4 100644 --- a/src/test/compile-fail/issue-32377.rs +++ b/src/test/compile-fail/issue-32377.rs @@ -21,7 +21,7 @@ struct Bar { fn foo(x: [usize; 2]) -> Bar { unsafe { mem::transmute(x) } - //~^ ERROR transmute called with differently sized types + //~^ ERROR transmute called with types of different sizes } fn main() {} diff --git a/src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs b/src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs index 43371eb6340f4..2d9de57a2659f 100644 --- a/src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs +++ b/src/test/compile-fail/lifetime-elision-return-type-requires-explicit-lifetime.rs @@ -28,7 +28,7 @@ struct Foo<'a> { // Lifetime annotation needed because we have two lifetimes: one as a parameter // and one on the reference. fn h(_x: &Foo) -> &isize { //~ ERROR missing lifetime specifier -//~^ HELP the signature does not say which one of `_x`'s 2 elided lifetimes it is borrowed from +//~^ HELP the signature does not say which one of `_x`'s 2 lifetimes it is borrowed from panic!() } diff --git a/src/test/compile-fail/packed-struct-generic-transmute.rs b/src/test/compile-fail/packed-struct-generic-transmute.rs index 2c345e6c8ab2b..c96184d598843 100644 --- a/src/test/compile-fail/packed-struct-generic-transmute.rs +++ b/src/test/compile-fail/packed-struct-generic-transmute.rs @@ -13,7 +13,7 @@ // the error points to the start of the file, not the line with the // transmute -// error-pattern: transmute called with differently sized types +// error-pattern: transmute called with types of different sizes use std::mem; diff --git a/src/test/compile-fail/packed-struct-transmute.rs b/src/test/compile-fail/packed-struct-transmute.rs index 94f2522f3eb34..abb02dd39e67d 100644 --- a/src/test/compile-fail/packed-struct-transmute.rs +++ b/src/test/compile-fail/packed-struct-transmute.rs @@ -13,7 +13,7 @@ // the error points to the start of the file, not the line with the // transmute -// error-pattern: transmute called with differently sized types +// error-pattern: transmute called with types of different sizes use std::mem; diff --git a/src/test/compile-fail/transmute-different-sizes.rs b/src/test/compile-fail/transmute-different-sizes.rs index 5fab271efce64..113e2ed4c80f4 100644 --- a/src/test/compile-fail/transmute-different-sizes.rs +++ b/src/test/compile-fail/transmute-different-sizes.rs @@ -17,12 +17,12 @@ use std::mem::transmute; unsafe fn f() { let _: i8 = transmute(16i16); - //~^ ERROR transmute called with differently sized types + //~^ ERROR transmute called with types of different sizes } unsafe fn g(x: &T) { let _: i8 = transmute(x); - //~^ ERROR transmute called with differently sized types + //~^ ERROR transmute called with types of different sizes } trait Specializable { type Output; } @@ -33,7 +33,7 @@ impl Specializable for T { unsafe fn specializable(x: u16) -> ::Output { transmute(x) - //~^ ERROR transmute called with differently sized types + //~^ ERROR transmute called with types of different sizes } fn main() {} diff --git a/src/test/compile-fail/transmute-fat-pointers.rs b/src/test/compile-fail/transmute-fat-pointers.rs index f7324247f3b4a..59027fc7787f8 100644 --- a/src/test/compile-fail/transmute-fat-pointers.rs +++ b/src/test/compile-fail/transmute-fat-pointers.rs @@ -15,11 +15,11 @@ use std::mem::transmute; fn a(x: &[T]) -> &U { - unsafe { transmute(x) } //~ ERROR transmute called with differently sized types + unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes } fn b(x: &T) -> &U { - unsafe { transmute(x) } //~ ERROR transmute called with differently sized types + unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes } fn c(x: &T) -> &U { @@ -31,11 +31,11 @@ fn d(x: &[T]) -> &[U] { } fn e(x: &T) -> &U { - unsafe { transmute(x) } //~ ERROR transmute called with differently sized types + unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes } fn f(x: &T) -> &U { - unsafe { transmute(x) } //~ ERROR transmute called with differently sized types + unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes } fn main() { } diff --git a/src/test/compile-fail/transmute-impl.rs b/src/test/compile-fail/transmute-impl.rs index 55cebbd6cfcbe..2f8f9e46e1aee 100644 --- a/src/test/compile-fail/transmute-impl.rs +++ b/src/test/compile-fail/transmute-impl.rs @@ -26,7 +26,7 @@ impl Foo { fn n(x: &T) -> &isize { // Not OK here, because T : Sized is not in scope. - unsafe { transmute(x) } //~ ERROR transmute called with differently sized types + unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes } } diff --git a/src/test/ui/transmute/main.rs b/src/test/ui/transmute/main.rs new file mode 100644 index 0000000000000..28cac90c69d9b --- /dev/null +++ b/src/test/ui/transmute/main.rs @@ -0,0 +1,36 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(untagged_unions)] +use std::mem::transmute; + +pub trait TypeConstructor<'a> { + type T; +} + +unsafe fn transmute_lifetime<'a, 'b, C>(x: >::T) + -> >::T +where for<'z> C: TypeConstructor<'z> { + transmute(x) //~ ERROR transmute called with types of different sizes +} + +unsafe fn sizes() { + let x: u8 = transmute(10u16); //~ ERROR transmute called with types of different sizes +} + +unsafe fn ptrs() { + let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes +} + +union Foo { x: () } +unsafe fn vary() { + let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes +} + +fn main() {} diff --git a/src/test/ui/transmute/main.stderr b/src/test/ui/transmute/main.stderr new file mode 100644 index 0000000000000..2ae4252cfa2b7 --- /dev/null +++ b/src/test/ui/transmute/main.stderr @@ -0,0 +1,38 @@ +error[E0512]: transmute called with types of different sizes + --> $DIR/main.rs:20:5 + | +20 | 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 + | +24 | 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 + | +28 | 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 + | +33 | let x: Foo = transmute(10); //~ ERROR transmute called with types of different sizes + | ^^^^^^^^^ + | + = note: source type: i32 (32 bits) + = note: target type: Foo (0 bits) + +error: aborting due to previous error(s) + diff --git a/src/test/compile-fail/transmute-from-fn-item-types-error.rs b/src/test/ui/transmute/transmute-from-fn-item-types-error.rs similarity index 86% rename from src/test/compile-fail/transmute-from-fn-item-types-error.rs rename to src/test/ui/transmute/transmute-from-fn-item-types-error.rs index c3fe1de895df9..adc5a2bc59665 100644 --- a/src/test/compile-fail/transmute-from-fn-item-types-error.rs +++ b/src/test/ui/transmute/transmute-from-fn-item-types-error.rs @@ -8,9 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-x86 fn() has different sizes dependent on platform + 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 @@ -29,8 +31,8 @@ unsafe fn foo() -> (isize, *const (), Option) { unsafe fn bar() { // Error as usual if the resulting type is not pointer-sized. mem::transmute::<_, u8>(main); - //~^ ERROR transmute called with differently sized types - //~^^ NOTE transmuting between 0 bits and 8 bits + //~^ ERROR transmute called with types of different sizes + //~^^ NOTE transmuting between fn() {main} and u8 mem::transmute::<_, *mut ()>(foo); //~^ ERROR is zero-sized and can't be transmuted @@ -41,7 +43,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 +60,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 new file mode 100644 index 0000000000000..dd97a29272ebe --- /dev/null +++ b/src/test/ui/transmute/transmute-from-fn-item-types-error.stderr @@ -0,0 +1,108 @@ +error[E0512]: transmute called with types of different sizes + --> $DIR/transmute-from-fn-item-types-error.rs:16:13 + | +16 | let i = mem::transmute(bar); + | ^^^^^^^^^^^^^^ + | + = 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:20:13 + | +20 | let p = mem::transmute(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:24:14 + | +24 | let of = mem::transmute(main); + | ^^^^^^^^^^^^^^ + | + = note: source type: fn() {main} + = 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:33:5 + | +33 | 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:37:5 + | +37 | mem::transmute::<_, *mut ()>(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:41:5 + | +41 | 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:46:5 + | +46 | 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:50:5 + | +50 | 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:54:5 + | +54 | 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:58:5 + | +58 | 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:63:5 + | +63 | 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/compile-fail/transmute-type-parameters.rs b/src/test/ui/transmute/transmute-type-parameters.rs similarity index 69% rename from src/test/compile-fail/transmute-type-parameters.rs rename to src/test/ui/transmute/transmute-type-parameters.rs index b6e7e32663ec1..ad2dcb10885c3 100644 --- a/src/test/compile-fail/transmute-type-parameters.rs +++ b/src/test/ui/transmute/transmute-type-parameters.rs @@ -13,18 +13,18 @@ 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 +32,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 +42,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 new file mode 100644 index 0000000000000..f837ebdc6fb21 --- /dev/null +++ b/src/test/ui/transmute/transmute-type-parameters.stderr @@ -0,0 +1,56 @@ +error[E0512]: transmute called with types of different sizes + --> $DIR/transmute-type-parameters.rs:16:18 + | +16 | let _: i32 = transmute(x); + | ^^^^^^^^^ + | + = note: source type: T (this type's size can vary) + = note: target type: i32 (32 bits) + +error[E0512]: transmute called with types of different sizes + --> $DIR/transmute-type-parameters.rs:21:18 + | +21 | let _: i32 = transmute(x); + | ^^^^^^^^^ + | + = 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:18 + | +26 | let _: i32 = transmute(x); + | ^^^^^^^^^ + | + = note: source type: [T; 10] (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:35:18 + | +35 | let _: i32 = transmute(x); + | ^^^^^^^^^ + | + = note: source type: Bad (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:45:18 + | +45 | let _: i32 = transmute(x); + | ^^^^^^^^^ + | + = note: source type: Worse (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:50:18 + | +50 | let _: i32 = transmute(x); + | ^^^^^^^^^ + | + = note: source type: std::option::Option (size can vary because of T) + = note: target type: i32 (32 bits) + +error: aborting due to previous error(s) +