-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow transmuting generic pattern types to and from their base #136179
base: master
Are you sure you want to change the base?
Conversation
How does this handle types containing pattern types, e.g. #![feature(pattern_types, pattern_type_macro)]
use std::pat::pattern_type;
fn foo<const N: u32>() {
std::mem::transmute::<Option<u32>, Option<pattern_type!(u32 is N..)>>(loop {});
} Which should not compile as those two options have different sizes when |
283b81c
to
660979c
Compare
These are still rejected accidentally. So good and bad. I think we can land this because there's no code path that could accidentally accept anything here (we explicitly check for pointers) |
660979c
to
a639e27
Compare
So I guess basically all the complex #![feature(pattern_types, pattern_type_macro)]
use std::pat::pattern_type;
struct Pointee<T>(T);
fn foo<T, U>() {
std::mem::transmute::<
Option<*mut Pointee<T>>,
Option<
pattern_type!(*mut Pointee<U> is /* nonnull */>
),
>,
>(loop {});
}
fn main() {} Which would just be a matter of checking if the pattern type is a nonnull pattern refinement and changing the Correct me if I'm wrong but I don't think you even support pointer refinement in pattern types right now so it seems like kind of moot to try and handle this correctly rn. |
@bors r+ rollup |
Yes, we'll have to look into that when we get there. |
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.