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

Conventions for the use of Deref and DerefMut #279

Open
rust-highfive opened this issue Sep 24, 2014 · 8 comments
Open

Conventions for the use of Deref and DerefMut #279

rust-highfive opened this issue Sep 24, 2014 · 8 comments
Labels
A-convention Proposals relating to documentation conventions. postponed RFCs that have been postponed and may be revisited at a later time. T-doc Relevant to the documentation team, which will review and decide on the RFC.

Comments

@rust-highfive
Copy link

This was discussed previously in rust-lang/rust#13126.

Tracking issue for postponed PR #25

@rust-highfive rust-highfive added the postponed RFCs that have been postponed and may be revisited at a later time. label Sep 24, 2014
@nrc
Copy link
Member

nrc commented Dec 25, 2014

I am keen to see some guidance here. In particular, I find deref'ing to an unrelated type for the sake of convenience a confusing anti-pattern. My preference would be for deref to only be used for getting the contents of a smart pointer and for taking a slice of a collection, but I'm sure there are other similar cases I haven't thought of. However, using deref for polymorphism using method calls seems pretty bad.

cc @aturon

@huonw
Copy link
Member

huonw commented Dec 26, 2014

What is 'unrelated'?

@aturon
Copy link
Member

aturon commented Dec 27, 2014

@nick29581 Yes, I am also anxious to establish some guidelines here; it's coming up increasingly often in std API designs.

@nrc
Copy link
Member

nrc commented Mar 6, 2015

Also InternedString in syntax::parse::token this is a wrapper around a wrapper around an Rc<str> and so it sort of makes sense for it to be Deref. However, to me that seems like an implementation detail, because it is advertised as a kind of string, rather than a smart pointer. So, it seems that Deref is wrong in this case. But perhaps it should be deref for the same reason String is. In any case it seems borderline and thus an interesting case to consider.

@brson
Copy link
Contributor

brson commented Mar 6, 2015

Derefing an InternedString in rustc can panic if the TLS invariants are violated, unlike with String.

@nrc
Copy link
Member

nrc commented Aug 17, 2016

@Centril Centril added the A-convention Proposals relating to documentation conventions. label Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-convention Proposals relating to documentation conventions. postponed RFCs that have been postponed and may be revisited at a later time. T-doc Relevant to the documentation team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

7 participants