{"id":"df4b02777f40888b","repo":"rust-lang/rust","slug":"sized-metasized-is-never-const","errorCode":null,"errorMessage":"Sized/MetaSized is never const","messagePattern":"Sized/MetaSized is never const","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_next_trait_solver/src/solve/effect_goals.rs","lineNumber":256,"sourceCode":"                    )\n                });\n            // While you could think of trait aliases to have a single builtin impl\n            // which uses its implied trait bounds as where-clauses, using\n            // `GoalSource::ImplWhereClause` here would be incorrect, as we also\n            // impl them, which means we're \"stepping out of the impl constructor\"\n            // again. To handle this, we treat these cycles as ambiguous for now.\n            ecx.add_goals(GoalSource::Misc, where_clause_bounds)?;\n            ecx.add_goals(GoalSource::Misc, const_conditions)?;\n            ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)\n        })\n    }\n\n    fn consider_builtin_sizedness_candidates(\n        _ecx: &mut EvalCtxt<'_, D>,\n        _goal: Goal<I, Self>,\n        _sizedness: SizedTraitKind,\n    ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {\n        unreachable!(\"Sized/MetaSized is never const\")\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        let cx = ecx.cx();\n\n        let self_ty = goal.predicate.self_ty();\n        let constituent_tys =\n            structural_traits::instantiate_constituent_tys_for_copy_clone_trait(ecx, self_ty)?;\n\n        ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {\n            ecx.enter_forall_with_assumptions(constituent_tys, goal.param_env, |ecx, tys| {\n                ecx.add_goals(\n                    GoalSource::ImplWhereBound,\n                    tys.into_iter().map(|ty| {\n                        goal.with(","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs#L238-L274","documentation":"At effect_goals.rs:256, `consider_builtin_sizedness_candidates` is marked `unreachable!` because the `Sized`/`MetaSized` built-in impl is intentionally never `const` in the host-effect (const-trait) system. The compiler should never ask `T: const Sized` — if it does, an upstream goal was assembled incorrectly. It is part of the `HostEffectPredicate` `GoalKind` assembly, so reaching it means a `const Sized` (or `const MetaSized`) goal reached candidate enumeration.","triggerScenarios":"Triggered when the next solver evaluates a `HostEffectPredicate` whose trait is `Sized` (lang item) with a const host effect — i.e. an internal goal like `T: const Sized` — and reaches the built-in sizedness candidate branch (effect_goals.rs:251).","commonSituations":"Nightly with `#![feature(host_effects)]` / `const_trait_impl` and a const trait bound that transitively forces a `const Sized` obligation (e.g. a `const fn` whose argument is `Sized`); mixing `~const` bounds with auto-trait assembly; regressions in how const conditions of const-callable items are propagated.","solutions":["Verify you are not indirectly requiring `const Sized` (e.g. via a `~const` where-clause on a const trait); remove or relax the bound.","Disable `-Znext-solver` and/or `const_trait_impl` to confirm the feature-gated path is responsible.","Reduce to a minimal `const fn`/`const trait` reproducer and report against the const-effects tracking issue on the Rust repo.","Upgrade nightly; const-effects is under active development and such ICEs are fixed frequently."],"exampleFix":"// before: ~const Sized leaking into host-effect assembly\nconst trait C { fn f(); }\nconst fn use_c<T: ~const C + Sized>(x: T) { T::f(); }\n\n// after: drop the redundant Sized host-effect obligation\nconst trait C { fn f(); }\nconst fn use_c<T: ~const C>(x: T) { T::f(); }","handlingStrategy":"validation","validationCode":"// Sized/MetaSized is provably non-const; reject any const context that depends on it.\nconst fn assert_not_sized_bound<T>() where T: Sized {} // compile error only if you try this in const-eval\n// Static rule enforced at review time: no `const fn` may have an implicit or explicit `Sized` bound that participates in const evaluation.","typeGuard":"// Guard a const-eval entry point against Sized-dependent code.\nfn const_entry_safe<T: ?Sized>() -> bool { false } // conservatively reject ?Sized in const paths","tryCatchPattern":null,"preventionTips":["Do not place `T: Sized` (or rely on the implicit Sized bound) inside `const fn` or `const { ... }` blocks that the next solver must evaluate.","Mark const entry points `where T: ?Sized` only if you also avoid any operation requiring Sized in the body.","Gate const-generic crates behind the next solver feature only where you have a concrete (non-Sized-bound) proof obligation."],"tags":["rustc-ice","const-traits","host-effects","sized","nightly","compiler-internal"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}