diff options
| author | bors <bors@rust-lang.org> | 2021-07-19 01:41:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-19 01:41:54 +0000 |
| commit | 10c0b003dbfee812788ac9f753a9b28bb3996b26 (patch) | |
| tree | 0cdadea0a7ae8e1642a981c0962fdae040921438 /compiler/rustc_mir/src/transform/coverage/graph.rs | |
| parent | b548d9f1c656953c3843693e060302c5c392d149 (diff) | |
| parent | e054522b01c841b5b30f40ef25615af03fcd9b27 (diff) | |
| download | rust-10c0b003dbfee812788ac9f753a9b28bb3996b26.tar.gz rust-10c0b003dbfee812788ac9f753a9b28bb3996b26.zip | |
Auto merge of #86848 - notriddle:notriddle/drop-dyn, r=varkor
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 'compiler/rustc_mir/src/transform/coverage/graph.rs')
0 files changed, 0 insertions, 0 deletions
