{"id":"6f525a10365c5040","repo":"rust-lang/rust","slug":"try-as-dyn-helper-trait-doesn-t-have-assoc-types","errorCode":null,"errorMessage":"try_as_dyn helper trait doesn't have assoc types","messagePattern":"try_as_dyn helper trait doesn't have assoc types","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs","lineNumber":1085,"sourceCode":"            return Err(NoSolution.into());\n        };\n        let def_id = goal.predicate.alias.expect_projection_ty_def_id();\n        let ty = match ecx.cx().as_projection_lang_item(def_id) {\n            Some(SolverProjectionLangItem::FieldBase) => base,\n            Some(SolverProjectionLangItem::FieldType) => ty,\n            _ => panic!(\"unexpected associated type {:?} in `Field`\", goal.predicate),\n        };\n        ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {\n            ecx.instantiate_normalizes_to_term(goal, ty.into())?;\n            ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)\n        })\n    }\n\n    fn consider_builtin_try_as_dyn_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"try_as_dyn helper trait doesn't have assoc types\")\n    }\n}\n\nimpl<D, I> EvalCtxt<'_, D>\nwhere\n    D: SolverDelegate<Interner = I>,\n    I: Interner,\n{\n    fn translate_args(\n        &mut self,\n        goal: Goal<I, ty::NormalizesTo<I>>,\n        impl_def_id: I::ImplId,\n        impl_args: I::GenericArgs,\n        impl_trait_ref: rustc_type_ir::TraitRef<I>,\n        target_container_def_id: I::DefId,\n    ) -> Result<I::GenericArgs, NoSolutionOrRerunNonErased> {\n        let cx = self.cx();\n        Ok(if target_container_def_id == impl_trait_ref.def_id.into() {","sourceCodeStart":1067,"sourceCodeEnd":1103,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs#L1067-L1103","documentation":"`try_as_dyn` is an internal helper trait used by the new reflection mode (to treat a concrete type as `dyn Trait`); it declares no associated types. The `unreachable!` at normalizes_to.rs:1085 in `consider_builtin_try_as_dyn_candidate` fires only if a `NormalizesTo` goal is assembled against this trait. Since there is nothing to normalize, dispatching a projection goal here means the solver constructed a malformed goal — a compiler bug.","triggerScenarios":"A `NormalizesTo` goal whose trait_ref is the `try_as_dyn` helper trait is routed into its builtin candidate, under `-Znext-solver` (most likely reflection mode).","commonSituations":"Nightly users running `-Znext-solver` with reflection (`-Znext-solver=reflection` / try-as-dyn experiments), or after a rustc update that rewires try_as_dyn candidate assembly.","solutions":["File/search an ICE at https://github.com/rust-lang/rust/issues with the panic text `try_as_dyn helper trait doesn't have assoc types`.","Drop `-Znext-solver` (and `-Znext-solver=reflection` in particular) from RUSTFLAGS / `.cargo/config.toml`.","`rustup update nightly`.","`cargo bisect-rustc` to pin the regression and attach it to the report."],"exampleFix":"// before — reflection/try_as_dyn experiment enabled\n// .cargo/config.toml: rustflags = [\"-Znext-solver=reflection\"]\n// after\n// .cargo/config.toml: rustflags = []","handlingStrategy":"type-guard","validationCode":"// `try_as_dyn` is an internal helper trait used by the solver to coerce\n// concrete types into dyn-trait objects. It has no associated types by design.\n// Do not attempt `<T as TryAsDyn<_>>::Assoc`.\nfn uses_dyn_correctly<T: ?Sized + Trait>(x: &T) -> &dyn Trait { x }","typeGuard":"// Avoid any type expression that projects an associated type off a dyn-coercion\n// helper. If you need a dyn-trait's type, project off the real user trait:\n// GOOD: <T as MyTrait>::Output\n// BAD:  <T as TryAsDyn<dyn MyTrait>>::Output   (helper has no assoc types)\ntrait MyTrait { type Output; }\n// If a macro generates these, audit the macro hygiene so it does not\n// accidentally reference the internal helper name.","tryCatchPattern":null,"preventionTips":["Never reference `try_as_dyn` or any solver-internal helper trait in user code; it is an implementation detail with no associated types.","Project associated types off the user-facing trait, not off dyn-coercion intermediaries.","Audit proc-macro / derive output for accidental references to internal trait names if this ICE appears."],"tags":["rustc","trait-solver","next-solver","ice","try-as-dyn","reflection"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}