Skip to content

Commit a75c21f

Browse files
committed
Rollup merge of rust-lang#27220 - AlisdairO:diagnostics120, r=Manishearth
As title! I should probably be bunching these up a bit more, but I'm not sure when my time is going to disappear on me. Once my schedule stabilises I'll try to start batching them into larger PRs. Part of rust-lang#24407. r? @Manishearth
2 parents fafb1fa + e668175 commit a75c21f

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,45 @@ fn main() {
13161316
```
13171317
"##,
13181318

1319+
E0120: r##"
1320+
An attempt was made to implement Drop on a trait, which is not allowed: only
1321+
structs and enums can implement Drop. An example causing this error:
1322+
1323+
```
1324+
trait MyTrait {}
1325+
1326+
impl Drop for MyTrait {
1327+
fn drop(&mut self) {}
1328+
}
1329+
```
1330+
1331+
A workaround for this problem is to wrap the trait up in a struct, and implement
1332+
Drop on that. An example is shown below:
1333+
1334+
```
1335+
trait MyTrait {}
1336+
struct MyWrapper<T: MyTrait> { foo: T }
1337+
1338+
impl <T: MyTrait> Drop for MyWrapper<T> {
1339+
fn drop(&mut self) {}
1340+
}
1341+
1342+
```
1343+
1344+
Alternatively, wrapping trait objects requires something like the following:
1345+
1346+
```
1347+
trait MyTrait {}
1348+
1349+
//or Box<MyTrait>, if you wanted an owned trait object
1350+
struct MyWrapper<'a> { foo: &'a MyTrait }
1351+
1352+
impl <'a> Drop for MyWrapper<'a> {
1353+
fn drop(&mut self) {}
1354+
}
1355+
```
1356+
"##,
1357+
13191358
E0121: r##"
13201359
In order to be consistent with Rust's lack of global type inference, type
13211360
placeholders are disallowed by design in item signatures.
@@ -2251,7 +2290,6 @@ register_diagnostics! {
22512290
E0103,
22522291
E0104,
22532292
E0118,
2254-
E0120,
22552293
E0122,
22562294
E0123,
22572295
E0127,

0 commit comments

Comments
 (0)