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.
Safe Transmute: Fix ICE (Inconsistent is_transmutable result)
This patch updates the code that constructs the `Assume` type to return an error instead of silently falling back to a default `Assume`. This fixes an ICE where error reporting would get a different `is_transmutable` result that is inconsistent with the original one computed during trait confirmation. Fixes rust-lang#110969
- Loading branch information
1 parent
39f42ad
commit 98ddc0f
Showing
12 changed files
with
147 additions
and
45 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
10 changes: 5 additions & 5 deletions
10
tests/ui/transmutability/issue-110892.stderr → ...ansmutability/issue-110892.current.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
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,42 @@ | ||
error: expected parameter name, found `,` | ||
--> $DIR/issue-110892.rs:29:9 | ||
| | ||
LL | , | ||
| ^ expected parameter name | ||
|
||
error: expected parameter name, found `,` | ||
--> $DIR/issue-110892.rs:30:9 | ||
| | ||
LL | , | ||
| ^ expected parameter name | ||
|
||
error: expected parameter name, found `,` | ||
--> $DIR/issue-110892.rs:31:9 | ||
| | ||
LL | , | ||
| ^ expected parameter name | ||
|
||
error: expected parameter name, found `,` | ||
--> $DIR/issue-110892.rs:32:9 | ||
| | ||
LL | , | ||
| ^ expected parameter name | ||
|
||
error[E0284]: type annotations needed: cannot satisfy `the constant `{ from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }` can be evaluated` | ||
--> $DIR/issue-110892.rs:23:13 | ||
| | ||
LL | { from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `the constant `{ from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }` can be evaluated` | ||
| | ||
note: required by a bound in `is_transmutable` | ||
--> $DIR/issue-110892.rs:23:13 | ||
| | ||
LL | pub fn is_transmutable< | ||
| --------------- required by a bound in this function | ||
... | ||
LL | { from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_transmutable` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0284`. |
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,15 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-110969.rs:26:74 | ||
| | ||
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>(); | ||
| ^^ expected `Assume`, found `()` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-110969.rs:26:29 | ||
| | ||
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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,15 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-110969.rs:26:74 | ||
| | ||
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>(); | ||
| ^^ expected `Assume`, found `()` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-110969.rs:26:29 | ||
| | ||
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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,30 @@ | ||
// check-fail | ||
// revisions: current next | ||
//[next] compile-flags: -Ztrait-solver=next | ||
#![feature(adt_const_params, generic_const_exprs, transmutability)] | ||
#![allow(incomplete_features)] | ||
|
||
mod assert { | ||
use std::mem::BikeshedIntrinsicFrom; | ||
|
||
pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>() | ||
where | ||
Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>, | ||
{ | ||
} | ||
} | ||
|
||
fn main() { | ||
struct Context; | ||
#[repr(C)] | ||
struct Src; | ||
#[repr(C)] | ||
struct Dst; | ||
|
||
trait Trait { | ||
// The `{}` should not cause an ICE | ||
const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>(); | ||
//~^ ERROR mismatched types | ||
//~^^ ERROR mismatched types | ||
} | ||
} |