From 7ed771f6c278961e9fd3ae0448898fca9a085cbe Mon Sep 17 00:00:00 2001 From: Stephen Lazaro Date: Sat, 3 Jun 2017 12:14:42 -0700 Subject: [PATCH 1/5] Remove 'elided' from lifetime resolution error Removes 'elided' from lifetime resolution errors Removes 'elided' from relevant error messaging tests --- src/librustc/middle/resolve_lifetime.rs | 2 +- src/test/compile-fail/issue-26638.rs | 2 +- src/test/compile-fail/issue-30255.rs | 6 +++--- ...fetime-elision-return-type-requires-explicit-lifetime.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) 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/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-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/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!() } From 8c005e9aadb338d14c7774f804e3168e66a8229d Mon Sep 17 00:00:00 2001 From: Mark Simulacrum Date: Mon, 29 May 2017 17:22:41 -0600 Subject: [PATCH 2/5] Update transmute size lints. Also moves a few transmute tests to UI tests to better test their output. --- src/librustc/diagnostics.rs | 2 +- src/librustc/middle/intrinsicck.rs | 26 ++---- src/test/compile-fail/E0512.rs | 1 - src/test/compile-fail/issue-21174.rs | 2 +- src/test/compile-fail/issue-28625.rs | 2 +- src/test/compile-fail/issue-32377.rs | 2 +- .../packed-struct-generic-transmute.rs | 2 +- .../compile-fail/packed-struct-transmute.rs | 2 +- .../compile-fail/transmute-different-sizes.rs | 6 +- .../compile-fail/transmute-fat-pointers.rs | 8 +- src/test/compile-fail/transmute-impl.rs | 2 +- src/test/ui/transmute/main.rs | 36 ++++++++ src/test/ui/transmute/main.stderr | 38 ++++++++ .../transmute-from-fn-item-types-error.rs | 4 +- .../transmute-from-fn-item-types-error.stderr | 91 +++++++++++++++++++ .../transmute}/transmute-type-parameters.rs | 0 .../transmute-type-parameters.stderr | 56 ++++++++++++ 17 files changed, 247 insertions(+), 33 deletions(-) create mode 100644 src/test/ui/transmute/main.rs create mode 100644 src/test/ui/transmute/main.stderr rename src/test/{compile-fail => ui/transmute}/transmute-from-fn-item-types-error.rs (94%) create mode 100644 src/test/ui/transmute/transmute-from-fn-item-types-error.stderr rename src/test/{compile-fail => ui/transmute}/transmute-type-parameters.rs (100%) create mode 100644 src/test/ui/transmute/transmute-type-parameters.stderr 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..de92395ac6955 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/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-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-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/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 94% 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..808be8beede92 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 @@ -29,8 +29,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 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..efd60630aa265 --- /dev/null +++ b/src/test/ui/transmute/transmute-from-fn-item-types-error.stderr @@ -0,0 +1,91 @@ +error[E0591]: can't transmute zero-sized type + --> $DIR/transmute-from-fn-item-types-error.rs:14:13 + | +14 | let i = mem::transmute(bar); + | ^^^^^^^^^^^^^^ + | + = note: source type: unsafe fn() {bar} + = note: target type: isize + = help: cast with `as` to a pointer instead + +error[E0591]: can't transmute zero-sized type + --> $DIR/transmute-from-fn-item-types-error.rs:18:13 + | +18 | let p = mem::transmute(foo); + | ^^^^^^^^^^^^^^ + | + = note: source type: unsafe fn() -> (isize, *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 + | +22 | 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:31:5 + | +31 | 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 + | +35 | mem::transmute::<_, *mut ()>(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:39:5 + | +39 | mem::transmute::<_, fn()>(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:48: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)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: source type: unsafe fn() {baz} + = note: target type: std::option::Option + = help: cast with `as` to a pointer instead + +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 100% rename from src/test/compile-fail/transmute-type-parameters.rs rename to src/test/ui/transmute/transmute-type-parameters.rs 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..39f18efe97a84 --- /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:20 + | +16 | let _: isize = transmute(x); + | ^^^^^^^^^ + | + = note: source type: T (this type's size can vary) + = note: target type: isize (64 bits) + +error[E0512]: transmute called with types of different sizes + --> $DIR/transmute-type-parameters.rs:21:20 + | +21 | let _: isize = transmute(x); + | ^^^^^^^^^ + | + = note: source type: (T, isize) (size can vary because of T) + = note: target type: isize (64 bits) + +error[E0512]: transmute called with types of different sizes + --> $DIR/transmute-type-parameters.rs:26:20 + | +26 | let _: isize = transmute(x); + | ^^^^^^^^^ + | + = note: source type: [T; 10] (size can vary because of T) + = note: target type: isize (64 bits) + +error[E0512]: transmute called with types of different sizes + --> $DIR/transmute-type-parameters.rs:35:20 + | +35 | let _: isize = transmute(x); + | ^^^^^^^^^ + | + = note: source type: Bad (size can vary because of T) + = note: target type: isize (64 bits) + +error[E0512]: transmute called with types of different sizes + --> $DIR/transmute-type-parameters.rs:45:20 + | +45 | let _: isize = transmute(x); + | ^^^^^^^^^ + | + = note: source type: Worse (size can vary because of T) + = note: target type: isize (64 bits) + +error[E0512]: transmute called with types of different sizes + --> $DIR/transmute-type-parameters.rs:50:20 + | +50 | let _: isize = transmute(x); + | ^^^^^^^^^ + | + = note: source type: std::option::Option (size can vary because of T) + = note: target type: isize (64 bits) + +error: aborting due to previous error(s) + From 7898f41faeeabbf17561e5233c4c80af41c77293 Mon Sep 17 00:00:00 2001 From: Mark Simulacrum Date: Sun, 4 Jun 2017 07:02:05 -0600 Subject: [PATCH 3/5] Update UI tests to be platform independent --- src/librustc/middle/intrinsicck.rs | 2 +- .../transmute-from-fn-item-types-error.rs | 8 ++- .../transmute-from-fn-item-types-error.stderr | 67 ++++++++++++------- .../ui/transmute/transmute-type-parameters.rs | 26 +++---- .../transmute-type-parameters.stderr | 50 +++++++------- 5 files changed, 86 insertions(+), 67 deletions(-) diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index de92395ac6955..f180ae53b8ae1 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -87,7 +87,7 @@ impl<'a, 'tcx> ExprVisitor<'a, '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/transmute-from-fn-item-types-error.rs b/src/test/ui/transmute/transmute-from-fn-item-types-error.rs index 808be8beede92..adc5a2bc59665 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,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 @@ -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 index efd60630aa265..dd97a29272ebe 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:16:13 | -14 | let i = mem::transmute(bar); +16 | 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:20:13 | -18 | let p = mem::transmute(foo); +20 | 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:24:14 | -22 | let of = mem::transmute(main); +24 | let of = mem::transmute(main); | ^^^^^^^^^^^^^^ | = note: source type: fn() {main} @@ -29,48 +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:33:5 | -31 | mem::transmute::<_, u8>(main); +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:35:5 + --> $DIR/transmute-from-fn-item-types-error.rs:37:5 | -35 | mem::transmute::<_, *mut ()>(foo); +37 | 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:41:5 | -39 | mem::transmute::<_, fn()>(bar); +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:48:5 + --> $DIR/transmute-from-fn-item-types-error.rs:50:5 | -48 | mem::transmute::<_, *mut ()>(Some(foo)); +50 | mem::transmute::<_, *mut ()>(Some(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:52:5 + --> $DIR/transmute-from-fn-item-types-error.rs:54:5 | -52 | mem::transmute::<_, fn()>(Some(bar)); +54 | mem::transmute::<_, fn()>(Some(bar)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: source type: unsafe fn() {bar} @@ -78,14 +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:56:5 + --> $DIR/transmute-from-fn-item-types-error.rs:58:5 | -56 | mem::transmute::<_, Option>(Some(baz)); +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/ui/transmute/transmute-type-parameters.rs b/src/test/ui/transmute/transmute-type-parameters.rs index b6e7e32663ec1..ad2dcb10885c3 100644 --- a/src/test/ui/transmute/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 index 39f18efe97a84..f837ebdc6fb21 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:16:18 | -16 | let _: isize = transmute(x); - | ^^^^^^^^^ +16 | 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:21:18 | -21 | let _: isize = transmute(x); - | ^^^^^^^^^ +21 | 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:26:18 | -26 | let _: isize = transmute(x); - | ^^^^^^^^^ +26 | 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:35:18 | -35 | let _: isize = transmute(x); - | ^^^^^^^^^ +35 | 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:45:18 | -45 | let _: isize = transmute(x); - | ^^^^^^^^^ +45 | 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:50:18 | -50 | let _: isize = transmute(x); - | ^^^^^^^^^ +50 | 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) From 40f8536449468d325e753c23e0e6fc2b45404154 Mon Sep 17 00:00:00 2001 From: Venkata Giri Reddy Date: Sun, 4 Jun 2017 18:35:57 +0000 Subject: [PATCH 4/5] rustc_llvm: re-run build script if config.toml changes --- src/bootstrap/compile.rs | 4 ++++ src/librustc_llvm/build.rs | 5 +++++ 2 files changed, 9 insertions(+) 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/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. From 018722e48599559a5488e4eab58b95d8d6fb75b8 Mon Sep 17 00:00:00 2001 From: king6cong Date: Mon, 5 Jun 2017 10:56:16 +0800 Subject: [PATCH 5/5] doc rewording --- src/libcore/marker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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`?