Skip to content

Commit

Permalink
Trait objects cannot contain associated constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Badel2 committed Feb 6, 2018
1 parent 6c04c41 commit 498ef20
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 498ef20

Please sign in to comment.