Skip to content

Commit

Permalink
Update compiler/rustc_error_codes/src/error_codes/E0120.md
Browse files Browse the repository at this point in the history
Co-authored-by: Trevor Gross <t.gross35@gmail.com>
  • Loading branch information
2 people authored and x420 committed Jul 19, 2024
1 parent e8f431f commit 8fbc5cb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_error_codes/src/error_codes/E0120.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Drop was implemented on a trait object or reference, which is not allowed; only
`Drop` was implemented on a trait object or reference, which is not allowed; only
structs, enums, and unions can implement Drop.

Erroneous code examples:
Expand All @@ -19,8 +19,8 @@ impl Drop for &'_ mut Concrete {
}
```

A workaround for traits is to wrap the trait up in a struct, and implement
Drop on that:
A workaround for traits is to create a wrapper struct with a generic type,
add a trait bound to the type, and implement `Drop` on the wrapper:

```
trait MyTrait {}
Expand All @@ -32,13 +32,13 @@ impl <T: MyTrait> Drop for MyWrapper<T> {
```

Alternatively, wrapping trait objects requires something:
Alternatively, `Drop` can be implemented on trait objects:

```
trait MyTrait {}
//or Box<MyTrait>, if you wanted an owned trait object
struct MyWrapper<'a> { foo: &'a MyTrait }
// or Box<dyn MyTrait>, if you wanted an owned trait object
struct MyWrapper<'a> { foo: &'a dyn MyTrait }
impl <'a> Drop for MyWrapper<'a> {
fn drop(&mut self) {}
Expand Down

0 comments on commit 8fbc5cb

Please sign in to comment.