Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0191: the value of the associated type `Bar` in `Trait` must be specified
What it meansAn associated type wasn't specified for a trait object.
What rustc prints
error[E0191]: the value of the associated type `Bar` in `Trait` must be specified --> main.rs:5:16 | 2 | type Bar; | -------- `Bar` defined here ... 5 | type Foo = dyn Trait; // error: the value of the associated type `Bar` (from | ^^^^^ | help: specify the associated type | 5 | type Foo = dyn Trait<Bar = /* Type */>; // error: the value of the associated type `Bar` (from | ++++++++++++++++++
Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
An associated type wasn't specified for a trait object.
Erroneous code example:
trait Trait {
type Bar;
}
type Foo = dyn Trait; // error: the value of the associated type `Bar` (from
// the trait `Trait`) must be specified
Trait objects need to have all associated types specified. Please verify that all associated types of the trait were specified and the correct trait was used. Example:
trait Trait {
type Bar;
}
type Foo = dyn Trait<Bar=i32>; // ok!From rustc --explain E0191 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0308mismatched types
- E0277the trait bound is not satisfied
- E0599no method named X found in the current scope
- E0433failed to resolve
- E0185method `foo` has a `&self` declaration in the impl, but not in the trait
- E0186method `foo` has a `&self` declaration in the trait, but not in the impl
- E0197inherent impls cannot be unsafe
- E0198negative impls cannot be unsafe
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?