Can we deprecate 'T: Drop' trait bounds?

#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.
4 Likes

Fixing the `Drop` trait bound
#2

Sounds like a useful clippy lint, at the very least.

4 Likes

#3

Please do. In fact, I was going to propose it as a part of a larger proposal to overhaul Drop.

0 Likes

#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?

0 Likes

#5

I’ve seen new Rust programmers try to use Drop bounds as “has a destructor”. I think a lint would definitely make sense!

2 Likes

closed #6

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

0 Likes