transmutability: model NonZero scalar ranges#148449
Conversation
|
|
||
| pub fn is_transmutable<Src, Dst>() | ||
| where | ||
| Dst: TransmuteFrom<Src, { Assume::NOTHING }>, |
There was a problem hiding this comment.
You probably want to Assume::SAFETY here, otherwise you're just getting sniped by field privacy.
There was a problem hiding this comment.
Doesn't look like it – see the .stderr output.
There was a problem hiding this comment.
Well that's not good; indicates we need to thread in the field visibility.
There was a problem hiding this comment.
Done – added a test to make sure we don't regress this.
There was a problem hiding this comment.
While you're poking around here, can you check that we didn't regress this on regular structs too? I think we might've.
There was a problem hiding this comment.
Do the existing tests in the safety directory cover this?
834cd59 to
fb550be
Compare
|
|
||
| pub fn is_transmutable<Src, Dst>() | ||
| where | ||
| Dst: TransmuteFrom<Src, { Assume::NOTHING }>, |
There was a problem hiding this comment.
Well that's not good; indicates we need to thread in the field visibility.
fb550be to
c9ec73b
Compare
|
@jswrenn While we're here, I've been experimenting with what it'd take to get this to the finish line (wiring things up so that the real |
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
|
Updated this PR to support |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Teach rustc_transmute to model scalar validity ranges for transparent std NonZero wrappers, including integer NonZero types and NonZero<char>. Also handle scalar-backed ADT layouts whose fields are represented with FieldsShape::Primitive. Thread the proving body through transmutability obligations so the trait solver can evaluate destination ADT, variant, and field safety invariants relative to the caller module. This keeps private fields and unsafe fields caller-sensitive in both old and next solver paths. Add UI coverage for std NonZero integers, NonZero<char>, option/array/ tuple compositions, same-width signed/unsigned conversions, reference safety invariants, and field visibility barriers.
Teach rustc_transmute to model scalar validity ranges for transparent
std NonZero wrappers, including integer NonZero types and NonZero.
Also handle scalar-backed ADT layouts whose fields are represented with
FieldsShape::Primitive.
Thread the proving body through transmutability obligations so the trait
solver can evaluate destination ADT, variant, and field safety
invariants relative to the caller module. This keeps private fields and
unsafe fields caller-sensitive in both old and next solver paths.
Add UI coverage for std NonZero integers, NonZero, option/array/
tuple compositions, same-width signed/unsigned conversions, reference
safety invariants, and field visibility barriers.
Tracking issue: #99571
r? @jswrenn