Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0575: cannot find associated type `Mythology` in trait `Age`
What it meansSomething other than a type or an associated type was given.
What rustc prints
error[E0575]: cannot find associated type `Mythology` in trait `Age` --> main.rs:16:21 | 8 | type Empire; | ------------ associated type `Empire` defined here ... 16 | let _: <u8 as Age>::Mythology; // error! | ^^^^^^^^^ not found in `Age` | = note: an associated function named `Age::Mythology` exists in another namespace help: maybe you meant this associated type | 16 - let _: <u8 as Age>::Mythology; // error! 16 + let _: <u8 as Age>::Empire; // error! |
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
Something other than a type or an associated type was given.
Erroneous code example:
enum Rick { Morty }
let _: <u8 as Rick>::Morty; // error!
trait Age {
type Empire;
fn Mythology() {}
}
impl Age for u8 {
type Empire = u16;
}
let _: <u8 as Age>::Mythology; // error!
In both cases, we're declaring a variable (called _) and we're giving it a type. However, <u8 as Rick>::Morty and <u8 as Age>::Mythology aren't types, therefore the compiler throws an error.
<u8 as Rick>::Morty is an enum variant, you cannot use a variant as a type, you have to use the enum directly:
enum Rick { Morty }
let _: Rick; // ok!
<u8 as Age>::Mythology is a trait method, which is definitely not a type. However, the Age trait provides an associated type Empire which can be used as a type:
trait Age {
type Empire;
fn Mythology() {}
}
impl Age for u8 {
type Empire = u16;
}
let _: <u8 as Age>::Empire; // ok!From rustc --explain E0575 (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
- E0573expected type, found variant `Dragon::Born`
- E0574expected struct, variant or union type, found module `mordor`
- E0576cannot find associated type `You` in trait `Hello`
- E0579lower bound for range pattern must be less than upper bound
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?