Email me

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.

E0575Types and traits
Activein rustc 1.99.0
8related errors linked below

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

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0308: mismatched typesA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ