{"id":"078028e1a6139f97","repo":"rust-lang/rust","slug":"unexpected-type-ty","errorCode":null,"errorMessage":"unexpected type `{ty:?}`","messagePattern":"unexpected type `(.+?)`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/trait_goals.rs","lineNumber":801,"sourceCode":"                | ty::CoroutineWitness(..) => {\n                    ecx.add_goal(\n                        GoalSource::ImplWhereBound,\n                        goal.with(\n                            cx,\n                            ty::TraitRef::new(\n                                cx,\n                                cx.require_trait_lang_item(SolverTraitLangItem::Copy),\n                                [ty],\n                            ),\n                        ),\n                    )?;\n                }\n\n                ty::Bound(..)\n                | ty::Infer(\n                    ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_),\n                ) => {\n                    panic!(\"unexpected type `{ty:?}`\")\n                }\n            }\n\n            ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)\n        })\n    }\n\n    /// ```ignore (builtin impl example)\n    /// trait Trait {\n    ///     fn foo(&self);\n    /// }\n    /// // results in the following builtin impl\n    /// impl<'a, T: Trait + 'a> Unsize<dyn Trait + 'a> for T {}\n    /// ```\n    fn consider_structural_builtin_unsize_candidates(\n        ecx: &mut EvalCtxt<'_, D>,\n        goal: Goal<I, Self>,\n    ) -> Result<Vec<Candidate<I>>, RerunNonErased> {","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs#L783-L819","documentation":"In the trait-goal version of `consider_builtin_bikeshed_guaranteed_no_drop_candidate` (trait_goals.rs:801), the match on `self_ty.kind()` panics for `ty::Bound(..)` and `ty::Infer(TyVar | FreshTy | FreshIntTy | FreshFloatTy)`. Such escaping-bound or unresolved type variables should be handled earlier (as ambiguous or by waiting for inference); reaching this arm means a not-yet-resolved type was passed into the builtin candidate — a solver-invariant violation.","triggerScenarios":"A `BikeshedGuaranteedNoDrop` trait goal whose self type is still a `Bound` var or an unbound `TyVar`/`Fresh*` inference variable reaches the builtin candidate during `-Znext-solver` evaluation.","commonSituations":"Nightly users with complex inference (generics, closures, async/coroutines, unsafe-binder) where a type variable isn't pinned before the drop-analysis builtin candidate runs; often after a rustc update or when combining `-Znext-solver` with staged inference.","solutions":["Report at https://github.com/rust-lang/rust/issues with the `{ty:?}` from the panic and a minimal repro.","Disable `-Znext-solver` to use the old solver which handles the ambiguous case differently.","Add explicit type annotations / turbofish to force inference before the builtin candidate runs.","`rustup update nightly` and `cargo bisect-rustc` to find the regression."],"exampleFix":"// before — type left inferred through a drop-sensitive position\nlet x = some_generic(); // BikeshedGuaranteedNoDrop goal on unknown type\n// after — annotate to resolve before the candidate runs\nlet x: MyType = some_generic::<MyType>();","handlingStrategy":"validation","validationCode":"// The trait-goal solver encountered an unexpected type kind (not a\n// nominal/generic/alias type it can reason about).\n// Validate that types used in trait bounds are fully-formed:\n// - concrete types, generic params, or associated-type aliases.\ntrait Valid {}\nimpl Valid for i32 {}\nfn use_bound<T: Valid>() {} // generic param: OK\nfn use_concrete() { use_bound::<i32>(); } // concrete: OK\n// Avoid: closures, fn pointers, or foreign types in unexpected bound positions.","typeGuard":"// Narrow to expected type kinds before constructing a trait goal.\n// In user code this means: provide concrete type annotations instead of\n// letting inference pick an unusual kind.\nfn with_explicit_type<T: Valid>(_: T) {}\n// Call with explicit turbofish to force a known kind:\n// with_explicit_type::<i32>(5);","tryCatchPattern":null,"preventionTips":["Provide explicit type annotations instead of relying on inference for unusual type kinds (closures, fn pointers, foreign items).","Avoid putting trait bounds on types the solver cannot normalise (raw closures, extern types).","When this ICE appears, reduce the trait bound to its simplest form and re-add constraints incrementally to isolate the offending type."],"tags":["rustc","trait-solver","next-solver","ice","bikeshed-guaranteed-no-drop","inference","bound-var"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}