{"id":"4cd924977f0f176a","repo":"rust-lang/rust","slug":"trait-aliases-do-not-have-associated-types","errorCode":null,"errorMessage":"trait aliases do not have associated types: {:?}","messagePattern":"trait aliases do not have associated types: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs","lineNumber":493,"sourceCode":"        ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {\n            ecx.instantiate_normalizes_to_term(goal, error_term)?;\n            ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)\n        })\n    }\n\n    fn consider_auto_trait_candidate(\n        ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        ecx.cx().delay_bug(\"associated types not allowed on auto traits\");\n        Err(NoSolution.into())\n    }\n\n    fn consider_trait_alias_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        panic!(\"trait aliases do not have associated types: {:?}\", goal);\n    }\n\n    fn consider_builtin_sizedness_candidates(\n        _ecx: &mut EvalCtxt<'_, D>,\n        goal: Goal<I, Self>,\n        _sizedness: SizedTraitKind,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        panic!(\"`Sized`/`MetaSized` does not have an associated type: {:?}\", goal);\n    }\n\n    fn consider_builtin_copy_clone_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        panic!(\"`Copy`/`Clone` does not have an associated type: {:?}\", goal);\n    }\n\n    fn consider_builtin_fn_ptr_trait_candidate(","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs#L475-L511","documentation":"A `panic!` in `consider_trait_alias_candidate`. Trait aliases (`trait Foo = Bar<Baz>;`) are pure sugar that expands to a set of where-clauses; they cannot declare or project associated types. If a `NormalizesTo` goal (`<T as Foo>::Item`) is dispatched against a trait alias, the solver has no associated item to project, so it panics — this indicates dispatch routed a projection goal to the alias assembly by mistake.","triggerScenarios":"A `NormalizesTo` goal whose trait ref refers to a trait alias (the `trait_alias` feature) is assembled by the candidate logic that should only fire for concrete traits. Reproducible with `#![feature(trait_alias)]` plus an attempt to name an associated item on the alias.","commonSituations":"Users of `trait_alias` who write `<T as MyAlias>::Item` expecting the alias to carry the associated type of its target (it does not — you must use the concrete trait ref).","solutions":["Rewrite the projection to use the concrete trait the alias expands to: replace `<T as MyAlias>::Item` with `<T as ConcreteTrait>::Item`.","Ensure the alias does not accidentally appear as the `trait_id` of a projection; expand aliases before building `NormalizesTo` goals.","If you maintain solver dispatch, confirm trait-alias candidates are skipped for `NormalizesTo` goals."],"exampleFix":"// before — projecting an associated type through a trait alias\n#![feature(trait_alias)]\ntrait Concrete { type Item; }\ntrait Alias = Concrete;\nfn f<T: Alias>() -> T::Item { todo!() } // ICE / wrong\n// after — project through the concrete trait\nfn f<T: Concrete>() -> T::Item { todo!() }\n","handlingStrategy":"validation","validationCode":"// Trait aliases are not allowed to have associated types. Detect a\n// trait-alias DefId before projecting.\nfn is_trait_alias(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {\n    matches!(tcx.def_kind(trait_def_id), DefKind::TraitAlias)\n}\nif is_trait_alias(tcx, did) {\n    return Err(\"cannot project associated type from a trait alias\");\n}","typeGuard":"fn is_real_trait_not_alias(tcx: TyCtxt<'_>, did: DefId) -> bool {\n    matches!(tcx.def_kind(did), DefKind::Trait)\n}","tryCatchPattern":"use std::panic;\nmatch panic::catch_unwind(panic::AssertUnwindSafe(|| solver.normalizes_to(goal))) {\n    Ok(v) => v,\n    Err(_) => Err(\"trait aliases carry no associated types; project through a concrete trait\"),\n}","preventionTips":["Never write `<T as MyAlias>::Assoc`; expand the alias to a concrete trait first.","Treat trait aliases as sugar for bounds, not as a projection target.","When you resolve an associated type, confirm the trait DefId is `DefKind::Trait`.","Document trait aliases as 'no associated types' so callers do not project through them."],"tags":["rustc","trait-solver","trait-alias","associated-types","compiler-internal","ice"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}