Skip to content

Conversation

@aerooneqq
Copy link
Contributor

@aerooneqq aerooneqq commented Dec 2, 2025

This PR relates to the delegation feature #118212, it fixes #144594 ICE.
r? @petrochenkov

@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 Dec 2, 2025
@petrochenkov petrochenkov added the F-fn_delegation `#![feature(fn_delegation)]` label Dec 2, 2025
@petrochenkov
Copy link
Contributor

Maybe it's better to fix check_unused_traits/lint_level_id_at_node somehow, instead of generation more detailed recovery HIR.
We don't generally require for all DefIds to appear in HIR (that's why MaybeOwner::Phantom exists), so the issue may potentially reproduce on something else than delegation.
Needs some investigation.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 2, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 2, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@aerooneqq
Copy link
Contributor Author

After the research the cause of the error was identified: during resolve stage and before HIR lowering the maybe_unused_trait_imports set is filled with candidate LocalDefIds of unused traits. Next, during the HIR analysis those candidates are checked in the check_unused_traits function. As those LocalDefIds were collected before HIR lowering, there might be situations when some parts of AST were not lowered to HIR (as in the current case #144594 or #137708). Then, when the lint is produced in node_span_lint method, eventually we end up using ParentHirIterator in order to walk from the current HirId up to the crate and get ICE when trying to obtain non-existing HirId for LocalDefId.

There are several options to fix this problem:

  1. Lower the delegation body when we failed to resolve delegation signature, thus we will have all requested HirIds,
  2. Check LocalDefId in check_unused_traits function for validity, i.e., we want to make sure that all LocalDefIds from the current one up to the root have corresponding HirId,
  3. Update ParentHirIterator so it will check whether the processed OwnerId and its parent have HirId,

I think we should stick with the first option for the following reasons:

  1. If we will add checks in check_unused_traits to ensure that all DefIds have corresponding HirId, we will make assumptions about the nature of node_span_lint method, because this upwalk is taken place there, this will result in abstraction leak, as the behavior of node_span_lint may change in the future but the check we potentially add in check_unused_traits method will remain,
  2. Updating ParentHirIterator with additional checks that HirIds exist for processed DefIds seems not correct, as firstly, if we do this, we should also update ParentOwnerIterator as it performs approximately the same routine and also crashes in this scenario, secondly, looking at the API that is provided to obtain HirIds, I believe that the invariant is that we should have a HirId for the DefId, addition of opt_ version of this APIs will break the current consistency, and it seems like it is the responsibility of the lowering stage to produce all required HirIds for DefIds,
  3. The ICE: No HirId for DefId #137708 issue that is almost identical with our issue ICE: delegation: No HirId for DefId #144594 was fixed by lowering parts of AST that were not lowered before, so I think that we want to be consistent with this fix,
  4. As maybe_unused_trait_imports are filled before HIR lowering, there are other ICEs that start from check_unused_traits function, they can be found using "check_unused::check_unused_traits" search (i.e., ICE type_of called on const argument's anon const before the const argument was lowered #148730), so if we will add protection from "No HirId for DefId" error there will be others that will probably bypass this check.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 5, 2025
@petrochenkov
Copy link
Contributor

r=me after addressing #149548 (comment) and squashing commits.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 5, 2025
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 5, 2025

📌 Commit 3e71712 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 5, 2025
bors added a commit that referenced this pull request Dec 5, 2025
Rollup of 11 pull requests

Successful merges:

 - #148662 (alloc: Document panics when allocations will exceed max)
 - #148811 (core docs: rewrite `panic::Location::caller` with visual line/column numbers)
 - #149101 (Improve mutable-binding suggestion to include name)
 - #149477 (float::maximum/minimum: make docs more streamlined)
 - #149547 (library: Rename `IterRange*` to `Range*Iter`)
 - #149548 (Generate delegation error body when delegation is not resolved)
 - #149630 (Check identifiers defined in macros when suggesting identifiers hidden by hygiene)
 - #149647 (Add regression test for 141845)
 - #149661 (Fix for LLVM22 making lowering decisions dependent on RuntimeLibraryInfo.)
 - #149666 (Add perma-unstable `--print=backend-has-zstd` for use by compiletest)
 - #149671 (interpret: test SNaN handling of float min/max and update comments)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c42ce16 into rust-lang:main Dec 5, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Dec 5, 2025
rust-timer added a commit that referenced this pull request Dec 5, 2025
Rollup merge of #149548 - aerooneqq:ice-issue-144594, r=petrochenkov

Generate delegation error body when delegation is not resolved

This PR relates to the delegation feature #118212, it fixes #144594 ICE.
r? `@petrochenkov`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Dec 6, 2025
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#148662 (alloc: Document panics when allocations will exceed max)
 - rust-lang/rust#148811 (core docs: rewrite `panic::Location::caller` with visual line/column numbers)
 - rust-lang/rust#149101 (Improve mutable-binding suggestion to include name)
 - rust-lang/rust#149477 (float::maximum/minimum: make docs more streamlined)
 - rust-lang/rust#149547 (library: Rename `IterRange*` to `Range*Iter`)
 - rust-lang/rust#149548 (Generate delegation error body when delegation is not resolved)
 - rust-lang/rust#149630 (Check identifiers defined in macros when suggesting identifiers hidden by hygiene)
 - rust-lang/rust#149647 (Add regression test for 141845)
 - rust-lang/rust#149661 (Fix for LLVM22 making lowering decisions dependent on RuntimeLibraryInfo.)
 - rust-lang/rust#149666 (Add perma-unstable `--print=backend-has-zstd` for use by compiletest)
 - rust-lang/rust#149671 (interpret: test SNaN handling of float min/max and update comments)

r? `@ghost`
`@rustbot` modify labels: rollup
@aerooneqq aerooneqq deleted the ice-issue-144594 branch December 7, 2025 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-fn_delegation `#![feature(fn_delegation)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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: delegation: No HirId for DefId

4 participants