about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-04-16 05:33:10 +0200
committerggomez <guillaume1.gomez@gmail.com>2016-04-26 11:16:36 +0200
commitd648fc68651c375189ae205f0f98fec9f66cdc44 (patch)
tree7409ca2dc7952ca10a165cd29c4bc762c49eeba3
parent772c600d4d6f39daa6d07d1a60ee0df3d3426978 (diff)
downloadrust-d648fc68651c375189ae205f0f98fec9f66cdc44.tar.gz
rust-d648fc68651c375189ae205f0f98fec9f66cdc44.zip
Add E0393 error explanation
-rw-r--r--src/librustc_typeck/diagnostics.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index bef6c1ed43a..db7ad844494 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -3426,6 +3426,37 @@ parameters. You can read more about it in the API documentation:
 https://doc.rust-lang.org/std/marker/struct.PhantomData.html
 "##,
 
+E0393: r##"
+A type parameter which references `Self` in its default value was not specified.
+Example of erroneous code:
+
+```compile_fail
+trait A<T=Self> {}
+
+fn together_we_will_rule_the_galaxy(son: &A) {}
+// error: the type parameter `T` must be explicitly specified in an
+//        object type because its default value `Self` references the
+//        type `Self`
+```
+
+A trait object is defined over a single, fully-defined trait. With a regular
+default parameter, this parameter can just be substituted in. However, if the
+default parameter is `Self`, the trait changes for each concrete type; i.e.
+`i32` will be expected to implement `A<i32>`, `bool` will be expected to
+implement `A<bool>`, etc... These types will not share an implementation of a
+fully-defined trait; instead they share implementations of a trait with
+different parameters substituted in for each implementation. This is
+irreconcilable with what we need to make a trait object work, and is thus
+disallowed. Making the trait concrete by explicitly specifying the value of the
+defaulted parameter will fix this issue. Fixed example:
+
+```
+trait A<T=Self> {}
+
+fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
+```
+"##,
+
 E0439: r##"
 The length of the platform-intrinsic function `simd_shuffle`
 wasn't specified. Erroneous code example:
@@ -3714,8 +3745,6 @@ register_diagnostics! {
            // between structures
     E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
            // between structures with the same definition
-    E0393, // the type parameter `{}` must be explicitly specified in an object
-           // type because its default value `{}` references the type `Self`"
     E0399, // trait items need to be implemented because the associated
            // type `{}` was overridden
     E0436, // functional record update requires a struct