forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#136179 - oli-obk:push-vxvyttorquxw, r=BoxyUwU Allow transmuting generic pattern types to and from their base Pattern types always have the same size as their base type, so we can just ignore the pattern and look at the base type for figuring out whether transmuting is possible.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![feature(pattern_types)] | ||
#![feature(pattern_type_macro)] | ||
|
||
use std::pat::pattern_type; | ||
|
||
// ok | ||
fn create<const S: u32, const E: u32>(x: u32) -> pattern_type!(u32 is S..=E) { | ||
unsafe { std::mem::transmute(x) } | ||
} | ||
|
||
// ok | ||
fn unwrap<const S: u32, const E: u32>(x: pattern_type!(u32 is S..=E)) -> u32 { | ||
unsafe { std::mem::transmute(x) } | ||
} | ||
|
||
// bad, only when S != u32::MIN or E != u32::MAX will this ok | ||
fn non_base_ty_transmute<const S: u32, const E: u32>( | ||
x: Option<pattern_type!(u32 is S..=E)>, | ||
) -> u32 { | ||
unsafe { std::mem::transmute(x) } | ||
//~^ ERROR types of different sizes | ||
} | ||
|
||
// bad, only when S = u32::MIN and E = u32::MAX will this ok | ||
fn wrapped_transmute<const S: u32, const E: u32>( | ||
x: Option<pattern_type!(u32 is S..=E)>, | ||
) -> Option<u32> { | ||
unsafe { std::mem::transmute(x) } | ||
//~^ ERROR 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,21 @@ | ||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types | ||
--> $DIR/transmute.rs:20:14 | ||
| | ||
LL | unsafe { std::mem::transmute(x) } | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: source type: `Option<(u32) is S..=E>` (size can vary because of u32) | ||
= note: target type: `u32` (32 bits) | ||
|
||
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types | ||
--> $DIR/transmute.rs:28:14 | ||
| | ||
LL | unsafe { std::mem::transmute(x) } | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: source type: `Option<(u32) is S..=E>` (size can vary because of u32) | ||
= note: target type: `Option<u32>` (64 bits) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0512`. |