]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_error_codes/src/error_codes/E0393.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0393.md
1 A type parameter which references `Self` in its default value was not specified.
2
3 Erroneous code example:
4
5 ```compile_fail,E0393
6 trait A<T=Self> {}
7
8 fn together_we_will_rule_the_galaxy(son: &A) {}
9 // error: the type parameter `T` must be explicitly specified in an
10 // object type because its default value `Self` references the
11 // type `Self`
12 ```
13
14 A trait object is defined over a single, fully-defined trait. With a regular
15 default parameter, this parameter can just be substituted in. However, if the
16 default parameter is `Self`, the trait changes for each concrete type; i.e.
17 `i32` will be expected to implement `A<i32>`, `bool` will be expected to
18 implement `A<bool>`, etc... These types will not share an implementation of a
19 fully-defined trait; instead they share implementations of a trait with
20 different parameters substituted in for each implementation. This is
21 irreconcilable with what we need to make a trait object work, and is thus
22 disallowed. Making the trait concrete by explicitly specifying the value of the
23 defaulted parameter will fix this issue. Fixed example:
24
25 ```
26 trait A<T=Self> {}
27
28 fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
29 ```