about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBadel2 <2badel2@gmail.com>2018-02-06 02:13:39 +0100
committerBadel2 <2badel2@gmail.com>2018-02-06 18:44:38 +0100
commit498ef20a2a2ce5da889440fb8708406b6f17e8d0 (patch)
tree3dce0992e134f6452b9b1a45d5dfb149ac25a6a6
parent6c04c41034c46730fba97bfe9cfa2dd0687c2a5f (diff)
downloadrust-498ef20a2a2ce5da889440fb8708406b6f17e8d0.tar.gz
rust-498ef20a2a2ce5da889440fb8708406b6f17e8d0.zip
Trait objects cannot contain associated constants
-rw-r--r--src/librustc/diagnostics.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index 8bd89b834d6..4c256556191 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -256,6 +256,28 @@ trait Foo {
 }
 ```
 
+### The trait cannot contain associated constants
+
+Just like static functions, associated constants aren't stored on the method
+table. If the trait or any subtrait contain an associated constant, they cannot
+be made into an object.
+
+```compile_fail,E0038
+trait Foo {
+    const X: i32;
+}
+
+impl Foo {}
+```
+
+A simple workaround is to use a helper method instead:
+
+```
+trait Foo {
+    fn x(&self) -> i32;
+}
+```
+
 ### The trait cannot use `Self` as a type parameter in the supertrait listing
 
 This is similar to the second sub-error, but subtler. It happens in situations