forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#42304 - Mark-Simulacrum:issue-37157, r=niko…
…matsakis Print the two types in the span label for transmute errors. Fixes rust-lang#37157. I'm not entirely happy with the changes here but overall it's better in my opinion; we certainly avoid the odd language in that issue, which changes to: ``` error[E0512]: transmute called with differently sized types: <C as TypeConstructor<'a>>::T (size can vary because of <C as TypeConstructor>::T) to <C as TypeConstructor<'b>>::T (size can vary because of <C as TypeConstructor>::T) --> test.rs:8:5 | 8 | ::std::mem::transmute(x) | ^^^^^^^^^^^^^^^^^^^^^ transmuting between <C as TypeConstructor<'a>>::T and <C as TypeConstructor<'b>>::T error: aborting due to previous error(s) ```
- Loading branch information
Showing
17 changed files
with
282 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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: <C as TypeConstructor<'a>>::T) | ||
-> <C as TypeConstructor<'b>>::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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: <C as TypeConstructor<'a>>::T (size can vary because of <C as TypeConstructor>::T) | ||
= note: target type: <C as TypeConstructor<'b>>::T (size can vary because of <C as TypeConstructor>::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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/test/ui/transmute/transmute-from-fn-item-types-error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<fn()>) {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<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: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<fn()>) {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::<fn(), u32>(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<fn()>) {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<fn()>>(Some(baz)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: source type: unsafe fn() {baz} | ||
= note: target type: std::option::Option<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:63:5 | ||
| | ||
63 | mem::transmute::<Option<fn()>, u32>(Some(main)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: source type: std::option::Option<fn()> (64 bits) | ||
= note: target type: u32 (32 bits) | ||
|
||
error: aborting due to previous error(s) | ||
|
Oops, something went wrong.