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