diff options
| author | Michael Howell <michael@notriddle.com> | 2021-07-03 11:20:01 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2021-07-18 07:55:57 -0700 |
| commit | dbd4fd5716fb53086e35aa5d1548f5f709e439a0 (patch) | |
| tree | 370fcc1d53a7ba536b430e99a0c621b676b6eeb4 /src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs | |
| parent | 18073052d8c3544ccb73effd289ed3acda0d66c0 (diff) | |
| download | rust-dbd4fd5716fb53086e35aa5d1548f5f709e439a0.tar.gz rust-dbd4fd5716fb53086e35aa5d1548f5f709e439a0.zip | |
feat(rustc_lint): add `dyn_drop`
Based on the conversation in #86747.
Explanation
-----------
A trait object bound of the form `dyn Drop` is most likely misleading
and not what the programmer intended.
`Drop` bounds do not actually indicate whether a type can be trivially
dropped or not, because a composite type containing `Drop` types does
not necessarily implement `Drop` itself. Naïvely, one might be tempted
to write a deferred drop system, to pull cleaning up memory out of a
latency-sensitive code path, using `dyn Drop` trait objects. However,
this breaks down e.g. when `T` is `String`, which does not implement
`Drop`, but should probably be accepted.
To write a trait object bound that accepts anything, use a placeholder
trait with a blanket implementation.
```rust
trait Placeholder {}
impl<T> Placeholder for T {}
fn foo(_x: Box<dyn Placeholder>) {}
```
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs')
0 files changed, 0 insertions, 0 deletions
