These are chat archives for rust-lang/rust

Jun 2017
Riley Dulin
Jun 10 2017 21:58

I had a question about a recursive definition of a trait (either how to do it, or how to do something similar which is better). I have this code:

trait ParseSymbol<L: Lexeme> {
    fn getProductions() -> Vec<Production<Self, L>>;

trait Production<P, L> where P: ParseSymbol<L>, L: Lexeme {
    fn getPieces() -> Vec<Piece<P, L>>;

enum Piece<P, L> where P: ParseSymbol<L>, L: Lexeme {

and it gives a compiler error

error[E0277]: the trait bound `parser::parser::Production<Self, L> + 'static: std::marker::Sized` is not satisfied
  --> src\parser\
14 |    fn getProductions() -> Vec<Production<Self, L>>;
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Sized` is not implemented for `parser::parser::Production<Self, L> + 'static`
   = note: `parser::parser::Production<Self, L> + 'static` does not have a constant size known at compile-time
   = note: required by `std::vec::Vec`
I have a feeling it's trying to get me to switch to a Box/trait objects, but I believe there's a solution which does not require runtime trait objects