-
Notifications
You must be signed in to change notification settings - Fork 13.9k
transmutability: Support types with restricted validity ranges #148449
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
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| pub fn is_transmutable<Src, Dst>() | ||
| where | ||
| Dst: TransmuteFrom<Src, { Assume::NOTHING }>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to Assume::SAFETY here, otherwise you're just getting sniped by field privacy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like it – see the .stderr output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that's not good; indicates we need to thread in the field visibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done – added a test to make sure we don't regress this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're poking around here, can you check that we didn't regress this on regular structs too? I think we might've.
| // types exist in the standard library which also | ||
| // use | ||
| // `#[rustc_layout_scalar_valid_range_(start|end)]`. | ||
| if let [field] = &variant.fields.as_slice().raw { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can de-indent a bunch of this if you let-else:
| if let [field] = &variant.fields.as_slice().raw { | |
| let [field] = &variant.fields.as_slice().raw else { return Err(Err::NotYetSupported) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
834cd59 to
fb550be
Compare
|
|
||
| pub fn is_transmutable<Src, Dst>() | ||
| where | ||
| Dst: TransmuteFrom<Src, { Assume::NOTHING }>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that's not good; indicates we need to thread in the field visibility.
| if hi_val == max_value | ||
| && let ty::Uint(_) = *field_ty.kind() | ||
| { | ||
| Ok(Self::nonzero(field_size.bytes())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Tree returned here should be a Seq of three elements:
- a
Tree::Def(Def::Adt(..))for the struct definition - a
Tree::Def(Def::Field(..))for the field definition - the
Self::nonzerofor the field layout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
This commit moves us closer to supporting `NonZero` types, but does not get us all the way there.
fb550be to
c9ec73b
Compare
This commit moves us closer to supporting
NonZerotypes, but does not get us all the way there.Tracking issue: #99571
r? @jswrenn