Skip to content

Fix ICE for ambiguous candidates on method probing - #162904

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
lsunsi:issue162857
Oct 2, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
lsunsi:issue162857

Conversation

@lsunsi

@lsunsi lsunsi commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #162857

It seems like the construction of the Pick was mixing two candidate information that were not synced:

  • if it is ambiguous
  • import ids

The two candidates were consistent, but the pick became inconsistent when they were mixed.
The fix was just to use the import_ids of the ambiguous candidate in case it exists, and keep old behavior otherwise.

ICE was introduced in #161805

Co-authored-by: Philip Sampaio <philip.sampaio@gmail.com>
@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 Sep 17, 2026
@rustbot

rustbot commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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 77 candidates
  • Random selection from 20 candidates

Comment thread compiler/rustc_hir_typeck/src/method/probe.rs Outdated
@folkertdev

Copy link
Copy Markdown
Contributor

r? types

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Sep 17, 2026
@rustbot rustbot assigned jackh726 and unassigned folkertdev Sep 17, 2026
Comment on lines +2386 to +2397
let ambiguously_imported_import_ids = probes.iter().find_map(|(p, _)| match p.kind {
TraitCandidate { is_ambiguously_imported, .. } => {
is_ambiguously_imported.then_some(p.import_ids)
}
_ => None,
});

let (is_ambiguously_imported, import_ids) = match ambiguously_imported_import_ids {
Some(import_ids) => (true, import_ids),
None => (false, probes[0].0.import_ids),
};

@jackh726 jackh726 Sep 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not combine these into a single match?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, this needs a comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 13e8826

Comment on lines 2386 to 2391
let ambiguously_imported_import_ids = probes.iter().find_map(|(p, _)| match p.kind {
TraitCandidate { is_ambiguously_imported, .. } => {
is_ambiguously_imported.then_some(p.import_ids)
}
_ => None,
});

@jackh726 jackh726 Sep 30, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would do something like:

Suggested change
let ambiguously_imported_import_ids = probes.iter().find_map(|(p, _)| match p.kind {
TraitCandidate { is_ambiguously_imported, .. } => {
is_ambiguously_imported.then_some(p.import_ids)
}
_ => None,
});
let ambiguous_candidate = probes.iter().find_map(|(p, _)| match p.kind {
TraitCandidate { is_ambiguously_imported: true, .. } => Some(p),
_ => None,
});
let (ambiguous, candidate) = ambiguous_candidate.map(|c| (true, c)).unwrap_or_else(|| (false, probes[0]));

And use this in place of probes[0] below.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 13e8826

@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 Sep 30, 2026
@rustbot

rustbot commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

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

@lsunsi

lsunsi commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@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 Sep 30, 2026
@jackh726

Copy link
Copy Markdown
Member

Please squash the last two commits into one

The ICE was caused because the code assumed the import_ids
would always be the same for all candidates, but it's not true.

Sometimes the candidate is ambiguous with import_ids to be logged
and sometimes the candidate is not ambigous and does not have the ids.

Mixing the two (flag = true, without import_ids) ICEs.

Co-authored-by: Philip Sampaio <philip.sampaio@gmail.com>
@lsunsi

lsunsi commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@jackh726 Done!

@jackh726

jackh726 commented Oct 1, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 109c917 has been approved by jackh726

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2026
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 1, 2026
Fix ICE for ambiguous candidates on method probing

Fixes rust-lang#162857

It seems like the construction of the Pick was mixing two candidate information that were not synced:
- if it is ambiguous
- import ids

The two candidates were consistent, but the pick became inconsistent when they were mixed.
The fix was just to use the import_ids of the ambiguous candidate in case it exists, and keep old behavior otherwise.

ICE was introduced in rust-lang#161805
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 1, 2026
Fix ICE for ambiguous candidates on method probing

Fixes rust-lang#162857

It seems like the construction of the Pick was mixing two candidate information that were not synced:
- if it is ambiguous
- import ids

The two candidates were consistent, but the pick became inconsistent when they were mixed.
The fix was just to use the import_ids of the ambiguous candidate in case it exists, and keep old behavior otherwise.

ICE was introduced in rust-lang#161805
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
Rollup of 11 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
@rust-bors
rust-bors Bot merged commit e970c24 into rust-lang:main Oct 2, 2026
13 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 2, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
Rollup merge of #162904 - lsunsi:issue162857, r=jackh726

Fix ICE for ambiguous candidates on method probing

Fixes #162857

It seems like the construction of the Pick was mixing two candidate information that were not synced:
- if it is ambiguous
- import ids

The two candidates were consistent, but the pick became inconsistent when they were mixed.
The fix was just to use the import_ids of the ambiguous candidate in case it exists, and keep old behavior otherwise.

ICE was introduced in #161805
@theemathas theemathas added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Oct 2, 2026
@lsunsi
lsunsi deleted the issue162857 branch October 2, 2026 10:36
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Oct 3, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - rust-lang/rust#163483 (Bump bootstrap compiler to 1.100.0 beta)
 - rust-lang/rust#161380 (only rerun const eval in next-solver if the const actually references opaques)
 - rust-lang/rust#162900 (Some refactorings around metadata encoding)
 - rust-lang/rust#163461 (Improve diagnostic deduplication)
 - rust-lang/rust#163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - rust-lang/rust#163584 ([triagebot] Ping me for debugger visualizer changes)
 - rust-lang/rust#159021 (windows-gnu: enable native TLS)
 - rust-lang/rust#161467 (wfcheck: name the item that discards an unused type parameter)
 - rust-lang/rust#162618 (trait_selection: Preserve eager normalization failures)
 - rust-lang/rust#162904 (Fix ICE for ambiguous candidates on method probing)
 - rust-lang/rust#163064 (Avoid computing overflowed goal chains for crate dependencies)
 - rust-lang/rust#163281 (Add `f16` inline ASM support to `spirv.rs`)
 - rust-lang/rust#163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - rust-lang/rust#163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - rust-lang/rust#163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - rust-lang/rust#163405 (Remove some #[linkage] options)
 - rust-lang/rust#163530 (`const impl PartialEq` for `f16b`)
 - rust-lang/rust#163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - rust-lang/rust#163590 (Make `AllocatorNightly` less clever)
 - rust-lang/rust#163599 (Add union pattern reference change to relnotes)
LorrensP-2158466 pushed a commit to LorrensP-2158466/miri that referenced this pull request Oct 6, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - rust-lang/rust#163483 (Bump bootstrap compiler to 1.100.0 beta)
 - rust-lang/rust#161380 (only rerun const eval in next-solver if the const actually references opaques)
 - rust-lang/rust#162900 (Some refactorings around metadata encoding)
 - rust-lang/rust#163461 (Improve diagnostic deduplication)
 - rust-lang/rust#163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - rust-lang/rust#163584 ([triagebot] Ping me for debugger visualizer changes)
 - rust-lang/rust#159021 (windows-gnu: enable native TLS)
 - rust-lang/rust#161467 (wfcheck: name the item that discards an unused type parameter)
 - rust-lang/rust#162618 (trait_selection: Preserve eager normalization failures)
 - rust-lang/rust#162904 (Fix ICE for ambiguous candidates on method probing)
 - rust-lang/rust#163064 (Avoid computing overflowed goal chains for crate dependencies)
 - rust-lang/rust#163281 (Add `f16` inline ASM support to `spirv.rs`)
 - rust-lang/rust#163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - rust-lang/rust#163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - rust-lang/rust#163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - rust-lang/rust#163405 (Remove some #[linkage] options)
 - rust-lang/rust#163530 (`const impl PartialEq` for `f16b`)
 - rust-lang/rust#163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - rust-lang/rust#163590 (Make `AllocatorNightly` less clever)
 - rust-lang/rust#163599 (Add union pattern reference change to relnotes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-nominated Nominated for backporting to the compiler in the beta channel. 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. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: index out of bounds: the len is 0 but the index is 0

5 participants