-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
implement Deref for Box. #19023
implement Deref for Box. #19023
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. |
Can you add a test for this? |
@gankro, what sort of test are you thinking? (It seems to me that the only sort of test that distinguishes between these (Metapoint: @sampsonwong and I wrote this together but have not had time to actually test if it compiles yet.) |
Doesn't derefing a box currently move the value out of the box? |
It can, but is not required to, e.g. |
I have a few questions: We already have built-in deref. By that I mean that
impl<Sized? T> Deref<T> for Box<T> {
fn deref(&self) -> &T { &**self }
} looks like it could end in a infinite recursive call, since
fn foo(s: Box<str>) {
let s: &mut str = &mut *s;
} works because of |
Yes, built-in operations override the overloaded ones (and I have checked).
It gives
and this diagnostic is certainly a bug (not one that needs to be addressed here). Either way, even if it worked, I don't know of any safe thing one can do with a |
Great, I asked because I read that you haven't tried compiling yet, but that probably was too long ago.
Sure, just curious if this opens the door to creating |
Yes I'd like to see a test confirming that this actually lets you do what it should, if only because the interaction with the built-in impl is delicate. |
ping @sampsonwong would you be willing to add a few tests to this PR along the lines of the comments? |
ee5ecb6
to
ec870b7
Compare
updated with a test case |
ping @sampsonwong, looks like the tests failed because of some tab characters |
Closing due to inactivity, but feel free to reopen with tests fixed! |
As the previous pull request (rust-lang#19023) was closed due to inactivity, I steal the chance and open this pull request. 😊 Fixes rust-lang#18624.
minor: Suggest better names when a type is a sequence
fixes #18624