ExpHP
1
Is there any legitimate use for a T: Drop
trait bound?
As far as I can tell:
- There are no methods you can call on a
T: Drop
.
- AFAICT the only thing that such a bound enables you do is to unsize a value to
dyn Drop
. (but what good is dyn Drop
for?)
- Usage of
T: Drop
for specialization is dangerous and wrong. The type (Vec<i32>, Vec<i32>)
does not impl Drop
. You should specialize on Copy
instead.
Edit (2019/09/5): Wow. There is a valid use case in pin-project
.
5 Likes
Sounds like a useful clippy lint, at the very least.
4 Likes
Please do. In fact, I was going to propose it as a part of a larger proposal to overhaul Drop
.
cuviper
4
Using Drop::drop
in any way is E0040, even just to mention it:
let _ = <Vec<i32> as Drop>::drop;
I could see a lint about Drop
bounds as an extension of this.
Have you seen T: Drop
in practice?
I’ve seen new Rust programmers try to use Drop
bounds as “has a destructor”. I think a lint would definitely make sense!
3 Likes
system
Closed
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.