Skip to content
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 #18624

Closed
kennytm opened this issue Nov 4, 2014 · 7 comments · Fixed by #20052
Closed

Implement Deref for Box #18624

kennytm opened this issue Nov 4, 2014 · 7 comments · Fixed by #20052
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@kennytm
Copy link
Member

kennytm commented Nov 4, 2014

As titled. Currently Box does not implement Deref:

fn f<G: Deref<int>>(g: &G) -> int { **g }
fn main() {
    f(&std::rc::Rc::new(1i));   // ok
    f(&box 1i); // error. Deref<int> not impl for Box<int>
}

But Box should be able to implement Deref.

impl<Sized? T> Deref<T> for Box<T> {
    fn deref(&self) -> &T { &**self }  // or any equivalent like `self.0.as_ref().unwrap()`
}
impl<Sized? T> DerefMut<T> for Box<T> {
    fn deref_mut(&mut self) -> &mut T { &mut **self }
}
@huonw huonw added A-libs E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Nov 14, 2014
@huonw
Copy link
Member

huonw commented Nov 14, 2014

(Tagged E-easy in the hope that it's as simple as adding the impls @kennytm gives in the issue. There is the chance that there is some compiler peculiarities that make this not-easy.)

@huonw huonw added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Nov 14, 2014
@huonw
Copy link
Member

huonw commented Nov 14, 2014

@nikomatsakis has kindly volunteered to mentor; catch him here or as nmatsakis on IRC.

@vojtechkral
Copy link
Contributor

Can I have a go at this? Looks easy enough... @nikomatsakis

@huonw
Copy link
Member

huonw commented Nov 19, 2014

@vojtechkral it's already been done/attempted in #19023. 😄

@vojtechkral
Copy link
Contributor

Oh well, never mind, I must've overlooked the cross-ref...

sampsonwong added a commit to sampsonwong/rust that referenced this issue Nov 24, 2014
@darnuria
Copy link
Contributor

@huonw This issue seems resolved due to #19023 close and merge.

@huonw
Copy link
Member

huonw commented Dec 18, 2014

@darnuria unfortunately it wasn't merged.

barosl added a commit to barosl/rust that referenced this issue Dec 19, 2014
alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 21, 2014
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants