-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Rc: remove unused allocation and fix segfault in Weak::new() #51901
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @RalfJung |
☔ The latest upstream changes (presumably #51569) made this pull request unmergeable. Please resolve the merge conflicts. |
0e51dd4
to
a309ea6
Compare
Rebased. |
src/liballoc/sync.rs
Outdated
} | ||
} | ||
} | ||
|
||
// Specialization because `NonNull::<T>::dangling()` only exits for `T: Sized` |
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.
Why not allow NonNull::<T>::dangling()
for T: ?Sized
instead?
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.
It wouldn’t compile because usize
can only be cast to thin pointers because we wouldn’t know what to use for the vtable pointer (for trait objects, for example).
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.
Oh, wait, I see now... this panics when actually called with something unsized? Is that really the desired behavior, for std::rc::Weak::<str>::new()
to panic?
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.
Ah, Weak::new
requires T: Sized
.
This seems rather hacky to have to write dangling_ptr
here but stub it out. At the very least, there should be a comment saying why this unimplemented!()
can never be hit. Actually, shouldn't it be unreachable!()
instead? unimplemented!()
to mean reads like "TODO: implement this".
Also, there are unsizing coercions for Weak
. Can't I use them to create a dangling Weak<[u8; 1]>
, then coerce that to Weak<[u8]>
and then run into problems because is_dangling
will now return false
?
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.
Sorry, I definitely should have commented this more clearly.
Yes, the idea was that Weak::new
only exists for T: Sized
. And yes, this is broken because I didn’t think of unsizing coecion. Good catch, thanks.
As pointed out by @RalfJung in inline comments, my attempt to making dangling pointers be aligned instead of having address 1 is broken. Even though The "obvious" fix would be to use With no way to find out the "real" alignment of a DST, I’m afraid we have no reliable way to check whether a pointer came from |
Notice that this is already happening right now when using unsizing coercions on I think we could declare that unsizing coercions effectively operate on raw pointers, similar to the |
Is the "payload" of fat raw pointers guaranteed to be valid, or is something like |
Good question. My inclination is that the vtable must always be a valid vtable, and the size of a raw slice must always be an integer (i.e., it must not be For example, I could imagine us doing enum layout optimizations based on the assumption that the vtable field is not NULL, and I think we could do these optimizations even for raw pointers. However, there may be crazy things people are doing that would be broken by this. ;) |
this is an under-defined part of the language |
Alright, I’ve changed
Adding a raw-pointer variation of |
r=me, but mind also adding some tests for DST coercions like casting a |
Done. @bors r=alexcrichton |
📌 Commit 96d1f27 has been approved by |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Fixed the error that happened with targets that don’t have atomic instructions (and so no @bors r=alexcrichton |
📌 Commit 67202b8 has been approved by |
…hton Rc: remove unused allocation and fix segfault in Weak::new() Same as rust-lang#50357 did for `Arc`. Fixes rust-lang#48493
Rollup of 9 pull requests Successful merges: - #51901 (Rc: remove unused allocation and fix segfault in Weak::new()) - #52058 (Use of unimplemented!() causing ICE with NLL) - #52067 (Visit the mir basic blocks in reverse-postfix order) - #52083 (Dont run ast borrowck on mir mode) - #52099 (fix typo in stable `--edition` error message) - #52103 (Stabilize rc_downcast) - #52104 (Remove unnecessary feature gate.) - #52117 (Dedupe filetime) - #52120 (ARM: expose the "mclass" target feature) Failed merges: r? @ghost
Correct outdated documentation for rc::Weak This was overlooked in ~~rust-lang#50357~~ rust-lang#51901
Same as #50357 did for
Arc
.Fixes #48493