]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0367.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0367.md
CommitLineData
60c5eb7d 1An attempt was made to implement `Drop` on a specialization of a generic type.
74b04a01
XL
2
3Erroneous code example:
60c5eb7d
XL
4
5```compile_fail,E0367
74b04a01 6trait Foo {}
60c5eb7d
XL
7
8struct MyStruct<T> {
9 t: T
10}
11
12impl<T: Foo> Drop for MyStruct<T> {
13 fn drop(&mut self) {}
14}
15```
16
17This code is not legal: it is not possible to specialize `Drop` to a subset of
18implementations of a generic type. In order for this code to work, `MyStruct`
19must also require that `T` implements `Foo`. Alternatively, another option is
20to wrap the generic type in another that specializes appropriately:
21
22```
23trait Foo{}
24
25struct MyStruct<T> {
26 t: T
27}
28
29struct MyStructWrapper<T: Foo> {
30 t: MyStruct<T>
31}
32
33impl <T: Foo> Drop for MyStructWrapper<T> {
34 fn drop(&mut self) {}
35}
36```