Skip to content

Skip non-fn-like defs before constructing their analyzer - #214

Merged
coord-e merged 1 commit into
mainfrom
claude/issue-198-fix-y22ljl
Aug 14, 2026
Merged

Skip non-fn-like defs before constructing their analyzer#214
coord-e merged 1 commit into
mainfrom
claude/issue-198-fix-y22ljl

Conversation

@coord-e

@coord-e coord-e commented Aug 13, 2026

Copy link
Copy Markdown
Owner

refine_local_defs built a local_def::Analyzer for every mir_keys entry and only dropped the non-fn-like ones at the end of the loop body. Analyzer::new fetches optimized_mir, which rustc forbids for const/static items, so a crate containing any such item aborted the compiler before verification started.

This moves the is_fn_like guard ahead of the local_def_analyzer call, matching what analyze_local_defs already does.

Checked against the reproductions in #198:

  • const K: i64 = 42; fn main() {} — now verifies
  • const K: i64 = 42; fn main() { let x = K; assert!(x == 42); } — now verifies
  • static S: i64 = 7; ... — no longer aborts the compiler; reaches unimplemented!("const ptr alloc: Static(..)") in const_value_ty
  • let a = [0i64; 3]; — no longer aborts the compiler; reaches unimplemented!("rvalue=[const 0_i64; 3]") in rvalue_type

The latter two are ordinary unsupported-construct panics, out of scope here.

No test cases added, per request.

Fixes #198


Generated by Claude Code

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
@coord-e
coord-e marked this pull request as ready for review August 14, 2026 00:42
@coord-e
coord-e requested a lite review from Copilot August 14, 2026 01:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the refine_local_defs loop.
  • Remove non-fn-like keys early (and continue) so local_def_analyzer is never created for const/static entries.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/analyze/crate_.rs
Comment on lines +68 to +71
if !self.tcx.def_kind(*local_def_id).is_fn_like() {
keys.swap_remove(local_def_id);
continue;
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@coord-e
coord-e merged commit 7d1b95e into main Aug 14, 2026
7 checks passed
@coord-e
coord-e deleted the claude/issue-198-fix-y22ljl branch August 14, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants