-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add a lint to warn on T: Drop
bounds
#3776
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
Conversation
Idk how hard it is to create a structured suggestion for this lint, but I'd be delighted if you tried to create one. Maybe modify a copy of the AST in place and pretty print that? |
I don't think suggestions would help very much. While "just remove the bound" would "fix" the code in the sense that it would stop the lint from firing and it wouldn't break anything that worked, the proper way to fix it is to switch to |
I also just realized that I hadn't actually tested this with |
94fb1bb
to
1d5710d
Compare
**What it does:** Checks for generics with `std::ops::Drop` as bounds. **Why is this bad?** `Drop` bounds do not really accomplish anything. A type may have compiler-generated drop glue without implementing the `Drop` trait itself. The `Drop` trait also only has one method, `Drop::drop`, and that function is by fiat not callable in user code. So there is really no use case for using `Drop` in trait bounds. **Known problems:** None. **Example:** ```rust fn foo<T: Drop>() {} ```
1d5710d
to
cb1c0b6
Compare
r=me with docs nit and travis passing |
Okay, @oli-obk. Fixed the formatting that Travis complained about and added the second paragraph to why-it's-bad. |
@bors r+ superb, thanks! |
📌 Commit bc4c3b6 has been approved by |
Add a lint to warn on `T: Drop` bounds **What it does:** Checks for generics with `std::ops::Drop` as bounds. **Why is this bad?** `Drop` bounds do not really accomplish anything. A type may have compiler-generated drop glue without implementing the `Drop` trait itself. The `Drop` trait also only has one method, `Drop::drop`, and that function is by fiat not callable in user code. So there is really no use case for using `Drop` in trait bounds. **Known problems:** None. **Example:** ```rust fn foo<T: Drop>() {} ``` Fixes #3773
☀️ Test successful - checks-travis, status-appveyor |
What it does: Checks for generics with
std::ops::Drop
as bounds.Why is this bad?
Drop
bounds do not really accomplish anything.A type may have compiler-generated drop glue without implementing the
Drop
trait itself. TheDrop
trait also only has one method,Drop::drop
, and that function is by fiat not callable in user code.So there is really no use case for using
Drop
in trait bounds.Known problems: None.
Example:
Fixes #3773