Skip to content

Commit e8f431f

Browse files
committed
fix: explain E0120 better cover cases when its raised
1 parent 5753b30 commit e8f431f

File tree

1 file changed

+12
-4
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+12
-4
lines changed

compiler/rustc_error_codes/src/error_codes/E0120.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Drop was implemented on a trait, which is not allowed: only structs and
2-
enums can implement Drop.
1+
Drop was implemented on a trait object or reference, which is not allowed; only
2+
structs, enums, and unions can implement Drop.
33

4-
Erroneous code example:
4+
Erroneous code examples:
55

66
```compile_fail,E0120
77
trait MyTrait {}
@@ -11,7 +11,15 @@ impl Drop for MyTrait {
1111
}
1212
```
1313

14-
A workaround for this problem is to wrap the trait up in a struct, and implement
14+
```compile_fail,E0120
15+
struct Concrete {}
16+
17+
impl Drop for &'_ mut Concrete {
18+
fn drop(&mut self) {}
19+
}
20+
```
21+
22+
A workaround for traits is to wrap the trait up in a struct, and implement
1523
Drop on that:
1624

1725
```

0 commit comments

Comments
 (0)