Skip non-fn-like defs before constructing their analyzer - #214
Conversation
refine_local_defs built a local_def::Analyzer for every mir_keys entry and only afterwards dropped the non-fn-like ones. Analyzer::new fetches optimized_mir, which rustc forbids for const and static items, so a crate containing any such item aborted the compiler before verification started. Move the is_fn_like guard ahead of the analyzer construction, as analyze_local_defs already does. Fixes #198 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WkS7GoCBGCCyj562jZQm7E
There was a problem hiding this comment.
Pull request overview
This PR fixes an ordering bug in local-crate analysis that could cause rustc to abort when the crate contains non-fn-like MIR keys (e.g., const/static items). It makes refine_local_defs skip non-fn-like defs before constructing a per-def analyzer, aligning it with analyze_local_defs and preventing an early optimized_mir query on unsupported item kinds.
Changes:
- Hoist the
def_kind(...).is_fn_like()guard to the top of therefine_local_defsloop. - Remove non-fn-like keys early (and
continue) solocal_def_analyzeris never created forconst/staticentries.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if !self.tcx.def_kind(*local_def_id).is_fn_like() { | ||
| keys.swap_remove(local_def_id); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Leaving this PR test-free intentionally — the author asked for the fix without new test cases. Worth noting for anyone adding one later: the natural pair here doesn't fit the pass/fail shape well, since the bug is an ICE rather than a soundness gap, so a fail counterpart would have to break the assertion rather than the guard being fixed.
The reproductions from #198 were verified by hand against this branch (results in the PR description).
Generated by Claude Code
refine_local_defsbuilt alocal_def::Analyzerfor everymir_keysentry and only dropped the non-fn-like ones at the end of the loop body.Analyzer::newfetchesoptimized_mir, which rustc forbids forconst/staticitems, so a crate containing any such item aborted the compiler before verification started.This moves the
is_fn_likeguard ahead of thelocal_def_analyzercall, matching whatanalyze_local_defsalready does.Checked against the reproductions in #198:
const K: i64 = 42; fn main() {}— now verifiesconst K: i64 = 42; fn main() { let x = K; assert!(x == 42); }— now verifiesstatic S: i64 = 7; ...— no longer aborts the compiler; reachesunimplemented!("const ptr alloc: Static(..)")inconst_value_tylet a = [0i64; 3];— no longer aborts the compiler; reachesunimplemented!("rvalue=[const 0_i64; 3]")inrvalue_typeThe latter two are ordinary unsupported-construct panics, out of scope here.
No test cases added, per request.
Fixes #198
Generated by Claude Code