{"id":"4a7e7f909edf3444","repo":"rust-lang/rust","slug":"unexpected-associated-item-for-self-ty","errorCode":null,"errorMessage":"unexpected associated item `{:?}` for `{self_ty:?}`","messagePattern":"unexpected associated item `(.+?)` for `(.+?)`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs","lineNumber":947,"sourceCode":"            return Err(NoSolution.into());\n        };\n\n        // `async`-desugared coroutines do not implement the coroutine trait\n        let cx = ecx.cx();\n        if !cx.is_general_coroutine(def_id) {\n            return Err(NoSolution.into());\n        }\n\n        let coroutine = args.as_coroutine();\n        let def_id = goal.predicate.alias.expect_projection_ty_def_id();\n\n        let term = if cx.is_projection_lang_item(def_id, SolverProjectionLangItem::CoroutineReturn)\n        {\n            coroutine.return_ty().into()\n        } else if cx.is_projection_lang_item(def_id, SolverProjectionLangItem::CoroutineYield) {\n            coroutine.yield_ty().into()\n        } else {\n            panic!(\"unexpected associated item `{:?}` for `{self_ty:?}`\", def_id)\n        };\n\n        Self::probe_and_consider_implied_clause(\n            ecx,\n            CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),\n            goal,\n            ty::ProjectionPredicate {\n                projection_term: ty::AliasTerm::new(\n                    ecx.cx(),\n                    goal.predicate.alias.kind,\n                    [self_ty, coroutine.resume_ty()],\n                ),\n                term,\n            }\n            .upcast(cx),\n            // Technically, we need to check that the coroutine type is Sized,\n            // but that's already proven by the coroutine being WF.\n            [],","sourceCodeStart":929,"sourceCodeEnd":965,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs#L929-L965","documentation":"consider_builtin_coroutine_candidate (normalizes_to.rs:947) handles projections for the Coroutine trait, which has exactly two associated types: CoroutineReturn and CoroutineYield (checked via is_projection_lang_item). The else arm at line 947 panics if the projection's def_id is neither — an invariant that the only well-formed coroutine projections are those two. It can only fire if the lang-item set contains a third coroutine projection that this match was not updated to recognize.","triggerScenarios":"A NormalizesTo goal for a Coroutine projection whose def_id is neither CoroutineReturn nor CoroutineYield reaches the builtin-coroutine candidate path, under -Znext-solver. Requires a rustc internal where a new coroutine associated item exists but this arm predates it, or goal construction produced a malformed projection.","commonSituations":"Using coroutines/generators (nightly `gen`, `coroutine` trait) on a bleeding-edge nightly with -Znext-solver; a toolchain regression during rustc coroutine-trait refactoring; not triggered by typical async/await (which uses the Future path, not Coroutine's own assoc types).","solutions":["Update to the latest nightly (rustup update nightly).","Disable -Znext-solver to fall back to the legacy solver.","File an ICE with the def_id and self_ty from the panic and a minimal reproducer (preferably using std::ops::Coroutine).","Avoid manually projecting coroutine associated types on the affected nightly; rely on generator/async desugaring instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Generic catch-all for an associated item that doesn't exist on Self.\n// Validate the item exists in the trait defn BEFORE projection:\ntrait Repo { fn get(&self, k: &str) -> u32; }   // only `get` exists\nfn use_repo<R: Repo>(r: &R) { let _ = r.get(\"x\"); } // OK\n","typeGuard":"// Compile-time check that the projected item name matches the trait declaration:\nconst _: fn() = || {\n    fn _check<R: Repo>(_: &R) {}\n};\n","tryCatchPattern":null,"preventionTips":["Cross-check every associated item name against the trait declaration before referencing it.","Avoid wildcard `use trait::*` which hides which items you actually project.","When implementing a foreign trait, copy item signatures verbatim from rustdoc."],"tags":["rust","rustc","trait-solver","next-solver","ice","panic","coroutine","associated-type","builtin-impl"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}