{"id":"cf1fba6625fb1c30","repo":"rust-lang/rust","slug":"fnptr-does-not-have-an-associated-type","errorCode":null,"errorMessage":"`FnPtr` does not have an associated type: {:?}","messagePattern":"`FnPtr` does not have an associated type: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs","lineNumber":515,"sourceCode":"        _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(\n        _ecx: &mut EvalCtxt<'_, D>,\n        goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        panic!(\"`FnPtr` does not have an associated type: {:?}\", goal);\n    }\n\n    fn consider_builtin_fn_trait_candidates(\n        ecx: &mut EvalCtxt<'_, D>,\n        goal: Goal<I, Self>,\n        goal_kind: ty::ClosureKind,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        let cx = ecx.cx();\n        let Some(tupled_inputs_and_output) =\n            structural_traits::extract_tupled_inputs_and_output_from_callable(\n                cx,\n                goal.predicate.self_ty(),\n                goal_kind,\n            )?\n        else {\n            return ecx.forced_ambiguity(MaybeInfo::AMBIGUOUS);\n        };\n        let (inputs, output) = ecx.instantiate_binder_with_infer(tupled_inputs_and_output);","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs#L497-L533","documentation":"A `panic!` in `consider_builtin_fn_ptr_trait_candidate`. The built-in `FnPtr` trait (the marker trait for fn pointers, distinct from the `Fn`/`FnMut`/`FnOnce` function-call traits) has no associated types, so a `NormalizesTo` goal against it should not reach this candidate. It indicates a dispatch mistake routing a projection goal into the fn-pointer candidate assembly.","triggerScenarios":"A `NormalizesTo` goal whose trait is `FnPtr` is dispatched to `consider_builtin_fn_ptr_trait_candidate` under the new solver. Reachable via IR that names an associated item on `FnPtr`.","commonSituations":"Nightly features around `FnPtr` (e.g. `fn_ptr_trait`); macro or compiler code that builds `<T as FnPtr>::Item`; regressions in how the solver filters candidates for marker-style builtin traits.","solutions":["Confirm `FnPtr` is never the trait of a projection goal; it is a marker, not a projection source.","Reduce and report as a rustc ICE with `-Znext-solver`.","Work around on the stable solver."],"exampleFix":"// before — projecting on the FnPtr marker trait (invalid)\nfn f<T: FnPtr>() -> <T as FnPtr>::Ret { todo!() }\n// after — use the Fn/FnOnce call trait for return-type projection\nfn f<F: FnOnce() -> i32>() -> F::Output { todo!() }\n","handlingStrategy":"validation","validationCode":"// FnPtr (the unboxed function-pointer marker) has no associated type.\nfn is_fnptr_trait(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {\n    tcx.lang_items().fn_ptr_trait() == Some(trait_def_id)\n}\nif is_fnptr_trait(tcx, did) {\n    return Err(\"FnPtr has no associated type\");\n}","typeGuard":"fn projection_target_is_not_fnptr(tcx: TyCtxt<'_>, did: DefId) -> bool {\n    tcx.lang_items().fn_ptr_trait() != Some(did)\n}","tryCatchPattern":"use std::panic;\nmatch panic::catch_unwind(panic::AssertUnwindSafe(|| solver.normalizes_to(goal))) {\n    Ok(v) => v,\n    Err(_) => Err(\"do not project an associated type off FnPtr; use Fn/FnMut/FnOnce instead\"),\n}","preventionTips":["Use `Fn`/`FnMut`/`FnOnce` (which do define `Output`) rather than the `FnPtr` trait.","Do not confuse the `FnPtr` trait with the `fn` type or the `Fn` family.","Project `Output` only via the closure traits, never via `FnPtr`.","Lint against `<T as FnPtr>::` in user code."],"tags":["rustc","trait-solver","fn-ptr","builtin-traits","associated-types","compiler-internal","ice"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}