Suppress self-referential associated type constraint suggestion#153921
Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom Mar 17, 2026
Merged
Conversation
Contributor
|
@bors r+ rollup |
Contributor
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Mar 17, 2026
…nstraint-suggestion, r=estebank Suppress self-referential associated type constraint suggestion Fixes rust-lang#112104 When comparing `Option<&I::Item>` against `Option<I::Item>`, the compiler decomposes the mismatch into `expected = &<I as Iterator>::Item` vs `found = <I as Iterator>::Item`. ARM 2 in `note_and_explain_type_err` matches because `found` is a projection, and would suggest `Item = &<I as Iterator>::Item` — constraining the associated type to something that contains itself. ARM 1 (`expected_projection`) already guards against this with `found.contains(expected)`. ARM 2 was missing the symmetric check. This adds `expected.contains(found)` to the match guard. Before: ```rust help: consider constraining the associated type `<I as Iterator>::Item` to `&<I as Iterator>::Item` | 1 | fn foo<I: Iterator<Item = &<I as Iterator>::Item>>(iter: &mut I) { | +++++++++++++++++++++++++++++++ ``` After: bogus suggestion is gone, and the existing `.as_ref()` suggestion from `hir_typeck` still fires correctly. r? @estebank
rust-bors bot
pushed a commit
that referenced
this pull request
Mar 17, 2026
Rollup of 5 pull requests Successful merges: - #146013 (Add `From` impls for wrapper types) - #153966 (suggest valid features when target feature is invalid) - #153372 (Fix LegacyKeyValueFormat report from docker build: x86_64-gnu) - #153738 (Don't look for non-type-level assoc consts when checking trait object types) - #153921 (Suppress self-referential associated type constraint suggestion)
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Mar 17, 2026
…nstraint-suggestion, r=estebank Suppress self-referential associated type constraint suggestion Fixes rust-lang#112104 When comparing `Option<&I::Item>` against `Option<I::Item>`, the compiler decomposes the mismatch into `expected = &<I as Iterator>::Item` vs `found = <I as Iterator>::Item`. ARM 2 in `note_and_explain_type_err` matches because `found` is a projection, and would suggest `Item = &<I as Iterator>::Item` — constraining the associated type to something that contains itself. ARM 1 (`expected_projection`) already guards against this with `found.contains(expected)`. ARM 2 was missing the symmetric check. This adds `expected.contains(found)` to the match guard. Before: ```rust help: consider constraining the associated type `<I as Iterator>::Item` to `&<I as Iterator>::Item` | 1 | fn foo<I: Iterator<Item = &<I as Iterator>::Item>>(iter: &mut I) { | +++++++++++++++++++++++++++++++ ``` After: bogus suggestion is gone, and the existing `.as_ref()` suggestion from `hir_typeck` still fires correctly. r? @estebank
rust-bors bot
pushed a commit
that referenced
this pull request
Mar 17, 2026
Rollup of 5 pull requests Successful merges: - #153966 (suggest valid features when target feature is invalid) - #153372 (Fix LegacyKeyValueFormat report from docker build: x86_64-gnu) - #153738 (Don't look for non-type-level assoc consts when checking trait object types) - #153907 (Remove redundant fields from `QueryStackFrame`) - #153921 (Suppress self-referential associated type constraint suggestion)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #112104
When comparing
Option<&I::Item>againstOption<I::Item>, the compiler decomposes the mismatch intoexpected = &<I as Iterator>::Itemvsfound = <I as Iterator>::Item. ARM 2 innote_and_explain_type_errmatches becausefoundis a projection, and would suggestItem = &<I as Iterator>::Item— constraining the associated type to something that contains itself.ARM 1 (
expected_projection) already guards against this withfound.contains(expected). ARM 2 was missing the symmetric check. This addsexpected.contains(found)to the match guard.Before:
After: bogus suggestion is gone, and the existing
.as_ref()suggestion fromhir_typeckstill fires correctly.r? @estebank