{"id":"851adc746352cd93","repo":"rust-lang/rust","slug":"field-is-not-const","errorCode":null,"errorMessage":"Field is not const","messagePattern":"Field is not const","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/effect_goals.rs","lineNumber":472,"sourceCode":"    fn consider_builtin_try_as_dyn_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"`TryAsDynCompat` is not const: {:?}\", goal)\n    }\n\n    fn consider_structural_builtin_unsize_candidates(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Vec<Candidate<I>>, RerunNonErased> {\n        unreachable!(\"Unsize is not const\")\n    }\n\n    fn consider_builtin_field_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<<D as SolverDelegate>::Interner, Self>,\n    ) -> Result<Candidate<<D as SolverDelegate>::Interner>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"Field is not const\")\n    }\n}\n\nimpl<D, I> EvalCtxt<'_, D>\nwhere\n    D: SolverDelegate<Interner = I>,\n    I: Interner,\n{\n    #[instrument(level = \"trace\", skip(self))]\n    pub(super) fn compute_host_effect_goal(\n        &mut self,\n        goal: Goal<I, ty::HostEffectPredicate<I>>,\n    ) -> QueryResultOrRerunNonErased<I> {\n        let (_, proven_via) = self.probe(|_| ProbeKind::ShadowedEnvProbing).enter(|ecx| {\n            let trait_goal: Goal<I, ty::TraitPredicate<I>> =\n                goal.with(ecx.cx(), goal.predicate.trait_ref);\n            ecx.compute_trait_goal(trait_goal).map_err(Into::into)\n        })?;","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs#L454-L490","documentation":"Internal `unreachable!` in the next-gen trait solver's const-effect candidate assembly for the built-in `Field` trait (`core::marker::Field`, part of the unsafe field-access / `proj` machinery). `Field` has no const implementation, so `consider_builtin_field_candidate` is a never-executed stub; reaching it means the solver routed a `T: const Field<...>` goal into built-in candidate assembly and the compiler ICEs.","triggerScenarios":"A host-effect goal resolves to the `Field` lang item: `T: const Field<F>` / `~const Field<F>`, typically via nightly field-projection (`proj`) experiments inside `const fn`, or a `#[const_trait]` whose implied bounds include `Field`.","commonSituations":"Using nightly field-projection / `unsafe` field-access features together with `const_trait_impl`; `-Znext-solver` on struct-projection-heavy generic code; nightly regression as field-trait routing was wired into effect-goal assembly.","solutions":["Remove the const/`~const Field` bound — field projection is not const.","Audit `#[const_trait]` traits for `Field` in their implied bounds.","Report the ICE upstream with a minimal reproducer and the `-Znext-solver`/`proj` feature flags.","Bisect nightlies; the Field trait and its const routing are highly unstable."],"exampleFix":"// before\nconst fn get<S, F>(s: &S) -> &F::Type where S: const Field<F> { unimplemented!() }\n\n// after\nfn get<S, F>(s: &S) -> &F::Type where S: Field<F> { unimplemented!() }","handlingStrategy":"validation","validationCode":"// build.rs: reject const Field (field-offset projection) bounds\nfn main() {\n    let src = std::fs::read_to_string(\"src/lib.rs\").unwrap_or_default();\n    for banned in [\"~const Field\", \"const Field\", \"core::field::Field\"] {\n        assert!(!src.contains(banned), \"rejected: {banned} — Field projection is not const\");\n    }\n    println!(\"cargo:rerun-if-changed=src/lib.rs\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["The `Field` projection trait (struct field access by name/path, behind `core::field`) has no const candidate (effect_goals.rs:472); do not demand `T: const Field<...>`.","In const code, access struct fields by direct `s.field` syntax, not through the `Field` trait.","Avoid generic field-projection helpers in `const fn`; specialize them or move to runtime.","An ICE here with no explicit `Field` bound means the solver mis-routed — report upstream."],"tags":["rustc","trait-solver","const-traits","ice","field-projection"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}