Skip to content

Commit

Permalink
fix: explain E0120 better cover cases when its raised
Browse files Browse the repository at this point in the history
  • Loading branch information
x420 committed Jul 19, 2024
1 parent 5753b30 commit e8f431f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0120.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Drop was implemented on a trait, which is not allowed: only structs and
enums can implement Drop.
Drop was implemented on a trait object or reference, which is not allowed; only
structs, enums, and unions can implement Drop.

Erroneous code example:
Erroneous code examples:

```compile_fail,E0120
trait MyTrait {}
Expand All @@ -11,7 +11,15 @@ impl Drop for MyTrait {
}
```

A workaround for this problem is to wrap the trait up in a struct, and implement
```compile_fail,E0120
struct Concrete {}
impl Drop for &'_ mut Concrete {
fn drop(&mut self) {}
}
```

A workaround for traits is to wrap the trait up in a struct, and implement
Drop on that:

```
Expand Down

0 comments on commit e8f431f

Please sign in to comment.