mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-28 03:07:24 +03:00
66c506d44a
Suppress self-referential associated type constraint suggestion Fixes rust-lang/rust#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