]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0367.md
Rollup merge of #66411 - RalfJung:forget, r=sfackler
[rust.git] / src / librustc_error_codes / error_codes / E0367.md
1 An attempt was made to implement `Drop` on a specialization of a generic type.
2 An example is shown below:
3
4 ```compile_fail,E0367
5 trait Foo{}
6
7 struct MyStruct<T> {
8     t: T
9 }
10
11 impl<T: Foo> Drop for MyStruct<T> {
12     fn drop(&mut self) {}
13 }
14 ```
15
16 This code is not legal: it is not possible to specialize `Drop` to a subset of
17 implementations of a generic type. In order for this code to work, `MyStruct`
18 must also require that `T` implements `Foo`. Alternatively, another option is
19 to wrap the generic type in another that specializes appropriately:
20
21 ```
22 trait Foo{}
23
24 struct MyStruct<T> {
25     t: T
26 }
27
28 struct MyStructWrapper<T: Foo> {
29     t: MyStruct<T>
30 }
31
32 impl <T: Foo> Drop for MyStructWrapper<T> {
33     fn drop(&mut self) {}
34 }
35 ```