-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #129364 - jswrenn:transmute-layout-errs, r=compiler-e…
…rrors safe transmute: gracefully bubble-up layout errors Changes `.unwrap()`s to `?` to avoid ICEs. Adds ui tests. Fixes #129327 Tracking Issue: #99571 r? `@compiler-errors`
- Loading branch information
Showing
9 changed files
with
121 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
26 changes: 26 additions & 0 deletions
26
tests/ui/transmutability/malformed-program-gracefulness/unknown_dst_field.rs
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,26 @@ | ||
// An unknown destination type should be gracefully handled. | ||
|
||
#![crate_type = "lib"] | ||
#![feature(transmutability)] | ||
#![allow(incomplete_features)] | ||
|
||
mod assert { | ||
use std::mem::BikeshedIntrinsicFrom; | ||
|
||
pub fn is_transmutable<Src, Dst>() | ||
where | ||
Dst: BikeshedIntrinsicFrom<Src> | ||
{} | ||
} | ||
|
||
fn should_gracefully_handle_unknown_dst_field() { | ||
#[repr(C)] struct Src; | ||
#[repr(C)] struct Dst(Missing); //~ cannot find type | ||
assert::is_transmutable::<Src, Dst>(); //~ ERROR cannot be safely transmuted | ||
} | ||
|
||
fn should_gracefully_handle_unknown_dst_ref_field() { | ||
#[repr(C)] struct Src(&'static Src); | ||
#[repr(C)] struct Dst(&'static Missing); //~ cannot find type | ||
assert::is_transmutable::<Src, Dst>(); //~ ERROR cannot be safely transmuted | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/ui/transmutability/malformed-program-gracefulness/unknown_dst_field.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,46 @@ | ||
error[E0412]: cannot find type `Missing` in this scope | ||
--> $DIR/unknown_dst_field.rs:18:27 | ||
| | ||
LL | #[repr(C)] struct Dst(Missing); | ||
| ^^^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `Missing` in this scope | ||
--> $DIR/unknown_dst_field.rs:24:36 | ||
| | ||
LL | #[repr(C)] struct Dst(&'static Missing); | ||
| ^^^^^^^ not found in this scope | ||
|
||
error[E0277]: `should_gracefully_handle_unknown_dst_field::Src` cannot be safely transmuted into `should_gracefully_handle_unknown_dst_field::Dst` | ||
--> $DIR/unknown_dst_field.rs:19:36 | ||
| | ||
LL | assert::is_transmutable::<Src, Dst>(); | ||
| ^^^ `should_gracefully_handle_unknown_dst_field::Dst` has an unknown layout | ||
| | ||
note: required by a bound in `is_transmutable` | ||
--> $DIR/unknown_dst_field.rs:12:14 | ||
| | ||
LL | pub fn is_transmutable<Src, Dst>() | ||
| --------------- required by a bound in this function | ||
LL | where | ||
LL | Dst: BikeshedIntrinsicFrom<Src> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_transmutable` | ||
|
||
error[E0277]: `should_gracefully_handle_unknown_dst_ref_field::Src` cannot be safely transmuted into `should_gracefully_handle_unknown_dst_ref_field::Dst` | ||
--> $DIR/unknown_dst_field.rs:25:36 | ||
| | ||
LL | assert::is_transmutable::<Src, Dst>(); | ||
| ^^^ `should_gracefully_handle_unknown_dst_ref_field::Dst` has an unknown layout | ||
| | ||
note: required by a bound in `is_transmutable` | ||
--> $DIR/unknown_dst_field.rs:12:14 | ||
| | ||
LL | pub fn is_transmutable<Src, Dst>() | ||
| --------------- required by a bound in this function | ||
LL | where | ||
LL | Dst: BikeshedIntrinsicFrom<Src> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_transmutable` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0412. | ||
For more information about an error, try `rustc --explain E0277`. |
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