Skip to content

Handle Node::Crate in generics_of to prevent ICE#155192

Closed
blackms wants to merge 2 commits intorust-lang:mainfrom
blackms:fix-ice-144888-generics-of-crate
Closed

Handle Node::Crate in generics_of to prevent ICE#155192
blackms wants to merge 2 commits intorust-lang:mainfrom
blackms:fix-ice-144888-generics-of-crate

Conversation

@blackms
Copy link
Copy Markdown

@blackms blackms commented Apr 12, 2026

Fixes #144888

The generics_of query did not handle Node::Crate, causing an ICE when the crate root DefId reached it during dyn-compatibility checking. The query stack was:

generics_of("") → dyn_compatibility_violations(Foo) → is_dyn_compatible(Foo) → …

The fix adds Node::Crate(_) to the existing match arm for nodes with no parent generics (alongside Node::Item and Node::ForeignItem), returning empty generics for the crate root. This is consistent with how other query implementations handle Node::Crate (e.g., resolve_bound_vars, check_well_formed).

r? compiler

The `generics_of` query did not handle `Node::Crate`, causing an ICE
when the crate root DefId was passed to it during dyn-compatibility
checking. This adds `Node::Crate(_)` to the match arm for nodes with
no parent generics, alongside `Node::Item` and `Node::ForeignItem`.

Fixes rust-lang#144888
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@rust-log-analyzer

This comment has been minimized.

The tidy check requires test file names to have the reason before the
issue number: {reason}-issue-{number}.rs
@cjgillot
Copy link
Copy Markdown
Contributor

generics_of should not be called on a module or crate. Should we prefer removing the offending call ?

@blackms
Copy link
Copy Markdown
Author

blackms commented Apr 12, 2026

You're right — I dug deeper and found that the offending caller was already fixed by #153615, which changed note_and_explain_type_err to pass Option<DefId> instead of the raw CRATE_DEF_ID. There's also already a test at tests/ui/dyn-compatibility/ice-generics-of-crate-root-152335.rs.

So this PR is redundant. I'll close it. Thanks for the pointer!

@blackms blackms closed this Apr 12, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: unhandled node Crate(Mod

5 participants