{"id":"f0ed033787438907","repo":"rust-lang/rust","slug":"transmutefrom-is-not-const","errorCode":null,"errorMessage":"TransmuteFrom is not const","messagePattern":"TransmuteFrom is not const","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_next_trait_solver/src/solve/effect_goals.rs","lineNumber":444,"sourceCode":"            ecx.add_goals(\n                GoalSource::AliasBoundConstCondition,\n                const_conditions.into_iter().map(|trait_ref| {\n                    goal.with(\n                        cx,\n                        ty::Binder::dummy(trait_ref)\n                            .to_host_effect_clause(cx, goal.predicate.constness),\n                    )\n                }),\n            )?;\n            ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)\n        })\n    }\n\n    fn consider_builtin_transmute_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"TransmuteFrom is not const\")\n    }\n\n    fn consider_builtin_bikeshed_guaranteed_no_drop_candidate(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"BikeshedGuaranteedNoDrop is not const\");\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!(\"`TryAsDynCompat` is not const: {:?}\", goal)\n    }\n\n    fn consider_structural_builtin_unsize_candidates(\n        _ecx: &mut EvalCtxt<'_, D>,","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs#L426-L462","documentation":"Internal `unreachable!` in the next-gen trait solver's const-effect candidate assembly for the built-in `TransmuteFrom` trait (`core::mem::TransmuteFrom`, the safe-transmute trait). Safe transmute has no const implementation, so `consider_builtin_transmute_candidate` exists only to satisfy the `GoalKind` interface and is never expected to run. Reaching it ICEs the compiler.","triggerScenarios":"A host-effect goal resolves to the `TransmuteFrom` lang item: code that requires `T: const TransmuteFrom<U>` / `~const TransmuteFrom<U>`, or that calls `mem::transmute`/safe-transmute APIs inside a `const fn` under `-Znext-solver`, forcing the solver to probe a const transmute candidate.","commonSituations":"Using nightly `safe_transmute`/`mem::transmute` inside `const fn`; generic const code over bitwise-reinterpretable types; enabling `-Znext-solver` on FFI/bytebuffer code; toolchain regression after transmute effect-goal routing landed.","solutions":["Do not put a const bound on `TransmuteFrom`; transmutation is not const-evaluable.","Hoist the transmute out of the `const fn` into runtime code, or precompute the value as a `static`/`const` of the target type.","Report the ICE upstream with a minimal reproducer (include `-Znext-solver` and the safe-transmute feature gate).","Bisect the nightly toolchain; transmute const routing is under active development."],"exampleFix":"// before\nconst fn reinterpret<U, T: const TransmuteFrom<U>>(u: U) -> T { unsafe { transmute(u) } }\n\n// after — compute at runtime\nfn reinterpret<U, T: TransmuteFrom<U>>(u: U) -> T { u.transmute_into() }","handlingStrategy":"validation","validationCode":"// build.rs: reject const TransmuteFrom (safe transmute) bounds\nfn main() {\n    let src = std::fs::read_to_string(\"src/lib.rs\").unwrap_or_default();\n    for banned in [\"~const TransmuteFrom\", \"const TransmuteFrom\", \"const core::mem::TransmuteFrom\"] {\n        assert!(!src.contains(banned), \"rejected: {banned} — TransmuteFrom has no const impl\");\n    }\n    println!(\"cargo:rerun-if-changed=src/lib.rs\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["`core::mem::TransmuteFrom` (safe transmute) has no const candidate (effect_goals.rs:444); do not demand `T: const TransmuteFrom<...>`.","For layout reinterpretation at runtime, use checked `bytemuck::TransparentWrapper`/`Pod` casts or explicit `transmute` behind a runtime function with your own size/align assertions.","In const code, convert types by explicit field-by-field construction rather than transmute.","Hitting this as an ICE without an explicit const bound indicates a solver routing bug; bisect nightly toolchains to find the regression."],"tags":["rustc","trait-solver","const-traits","ice","transmute","safe-transmute"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}