{"record":{"id":"8fc190d57cbbddbc","repo":"rust-lang/rust","slug":"reservation-impl-for-trait-with-assoc-item","errorCode":null,"errorMessage":"reservation impl for trait with assoc item: {:?}","messagePattern":"reservation impl for trait with assoc item: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs","lineNumber":275,"sourceCode":"        then: impl FnOnce(&mut EvalCtxt<'_, D>, Certainty) -> QueryResultOrRerunNonErased<I>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        let cx = ecx.cx();\n\n        let alias_def_id = goal.predicate.alias.expect_projection_def_id();\n        let goal_trait_ref = goal.predicate.alias.trait_ref(cx);\n        let impl_trait_ref = cx.impl_trait_ref(impl_def_id);\n        if !DeepRejectCtxt::relate_rigid_infer(ecx.cx())\n            .args_may_unify(goal_trait_ref.args, impl_trait_ref.skip_binder().args)\n        {\n            return Err(NoSolution.into());\n        }\n\n        // We have to ignore negative impls when projecting.\n        let impl_polarity = cx.impl_polarity(impl_def_id);\n        match impl_polarity {\n            ty::ImplPolarity::Negative => return Err(NoSolution.into()),\n            ty::ImplPolarity::Reservation => {\n                unimplemented!(\"reservation impl for trait with assoc item: {:?}\", goal)\n            }\n            ty::ImplPolarity::Positive => {}\n        };\n\n        ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {\n            let impl_args = ecx.fresh_args_for_item(impl_def_id.into());\n            let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args).skip_norm_wip();\n\n            ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;\n\n            let where_clause_bounds = cx\n                .clauses_of(impl_def_id.into())\n                .iter_instantiated(cx, impl_args)\n                .map(Unnormalized::skip_norm_wip)\n                .map(|clause| goal.with(cx, clause));\n            ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?;\n\n            // Bail if the nested goals don't hold here. This is to avoid unnecessarily","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs#L257-L293","documentation":"This panic comes from the next-generation trait solver when it tries to project (normalize) an associated type and finds that the matching impl is a *reservation* impl (ImplPolarity::Reservation) on a trait that has associated items. Reservation impls are reserved for special uses (e.g. future default impls in trait-system-refactor work); combining them with associated-type projection is not yet implemented, so the solver bails with unimplemented!() rather than producing a wrong answer.","triggerScenarios":"Compiling code that exercises both a reservation impl (#[const_trait] / reserved impls) and an associated item projection on the same trait under the next trait solver (RUSTFLAGS='-Znext-solver' or '-Ztrait-solver=next'). The match arm at normalizes_to.rs:272-276 hits ImplPolarity::Reservation for a goal whose alias has a projection def id.","commonSituations":"Nightly-only feature experiments with const traits / reservation impls, generic code that projects <T as Trait>::Assoc where Trait has a reservation impl, or running the new solver on crates that rely on unstable trait features. These are compiler-internal limitations, not user API misuse.","solutions":["Do not combine a reservation impl with associated items on the same trait; split the trait or remove the reservation polarity.","Avoid projecting the associated item; compute the value through a separate where-bound or helper trait without a reservation impl.","Run on the classic (old) solver instead: drop '-Znext-solver' / '-Ztrait-solver=next' from RUSTFLAGS.","Report/file a rustc issue with the minimized reproduction; this is a known gap in the next solver."],"exampleFix":"// before\ntrait Trait {\n    type Assoc;\n}\nimpl<T: ?Sized> ~const Trait for &T /* reservation-ish */ {\n    type Assoc = ();\n}\n\n// after: keep reservation impl away from associated items\ntrait Trait {\n    type Assoc;\n}\nimpl<T: ?Sized> Trait for &T {\n    type Assoc = ();\n}","handlingStrategy":"validation","validationCode":"// Before relying on projecting an associated item, check the impl polarity\n// via rustdoc/nightly queries; or assert at build time that the trait has no\n// reservation impl with associated items.\n// (Compiler-internal; cannot be validated at runtime.)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not mix reservation impls with associated items on the same trait.","Prefer the classic solver when experimenting with unstable trait features.","Track the trait-system-refactor-initiative issues before relying on reservation impls."],"tags":["rustc","trait-solver","nightly","compiler-internal","reservation-impl"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}