Skip to content

Avoid ICE when an EII declaration conflicts with a constructor#153571

Open
TaKO8Ki wants to merge 3 commits intorust-lang:mainfrom
TaKO8Ki:eii-ice-153502
Open

Avoid ICE when an EII declaration conflicts with a constructor#153571
TaKO8Ki wants to merge 3 commits intorust-lang:mainfrom
TaKO8Ki:eii-ice-153502

Conversation

@TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented Mar 8, 2026

Fixes #153502

When an #[eii] declaration conflicts with a tuple-struct constructor of the same name, error recovery can resolve
the EII target to the constructor instead of the generated foreign item. compare_eii_function_types then assumes
that target is a foreign function and later ICEs while building diagnostics.

This pull request adds an early guard in compare_eii_function_types to skip EII signature comparison unless the resolved target is actually a foreign function.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 8, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 8, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 8, 2026

r? @dingxiangfei2009

rustbot has assigned @dingxiangfei2009.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 15 candidates

@Kivooeo
Copy link
Member

Kivooeo commented Mar 8, 2026

cc @jdonszelmann

@jdonszelmann
Copy link
Contributor

r? me

sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
Some(sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span())))
} else {
panic!("expected {def_id:?} to be a foreign function");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change relevant given the early return at the top if it's not a foreign function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we have foreign function guard, it seems better to keep this line as it is or remove the panic and change it to:

let declaration_args = declaration.as_local().and_then(|def_id| {
      get_declaration_sig(tcx, def_id)
          .map(|sig| sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span())))
});

@jdonszelmann
Copy link
Contributor

@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 Mar 9, 2026
@TaKO8Ki
Copy link
Member Author

TaKO8Ki commented Mar 9, 2026

@rustbot review

@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 Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: expected DefId to be a foreign function

5 participants