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

Disallow the use of Drop as a bound #20151

Closed
ftxqxd opened this issue Dec 23, 2014 · 8 comments
Closed

Disallow the use of Drop as a bound #20151

ftxqxd opened this issue Dec 23, 2014 · 8 comments
Labels
A-traits Area: Trait system A-typesystem Area: The type system

Comments

@ftxqxd
Copy link
Contributor

ftxqxd commented Dec 23, 2014

It’s pretty useless to do so, and we might find a use for it post-1.0 for something like &out/&uninit that can’t be dropped.

@sfackler
Copy link
Member

Why should Drop be the only trait in existence that can't be used as a bound?

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Dec 23, 2014

Drop is already a lang item. Calling Drop::drop explicitly is disallowed (for safety reasons), so it’s already special. We might want to change the behaviour of using Drop as a bound in the future, so disallowing it for now would make that a backwards-compatible change. Drop as a bound is basically useless because it doesn’t mean that the type has no destructor, it just means that it doesn’t explicitly implement Drop (e.g., struct Foo(TypeThatImplsDrop); does not impl Drop, but still uses TypeThatImplsDrop’s Drop impl as part of its destructor). Drop is barely a normal trait at all. It has a method, but that method can’t ever be called explicitly. I think that Drop being a trait is merely a convenience that stops us from having to add a special way of adding destructors to things. It certainly should never be used as a bound.

@sfackler
Copy link
Member

This should probably live in rust-lang/rfcs, btw.

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Dec 23, 2014

We don’t have a strict set of rules about when to put issues in the RFCs repo, so I wasn’t sure about where to put this issue. It’s a pretty minor thing, though—no code should be using Drop as a bound today. RFCs issues are (as I understand them) basically placeholders for full RFCs. I think an RFC for something as minor as this might be unnecessary. I’m really not sure, though.

@pythonesque
Copy link
Contributor

I can't think of a reason you'd want it as a bound but I don't see why that means it shouldn't be legal. I can't think of a reason you'd use StrPrelude as a bound either, but it's still not disallowed. It would be better to go in the other direction and make drop take self instead of &mut self so it could be called as a normal function (IIRC that's the only reason it can't be called? Obviously the code generation would still be different).

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Dec 23, 2014

But we might want to allow Drop as a bound in the future with some other meaning. Disallowing it as a bound now will give us the flexibility to add a better meaning backwards-compatibly later.

@pythonesque
Copy link
Contributor

There's nothing stopping people from writing a new trait called Drop, though. We have multiple Slices even though one of them is in the prelude.

@kmcallister kmcallister added A-typesystem Area: The type system A-traits Area: Trait system labels Jan 16, 2015
@steveklabnik
Copy link
Member

These days, a change like this would require an RFC. @P1start if you still feel strongly about this, please file one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

5 participants