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