diff options
| author | Lukas Wirth <me@lukaswirth.dev> | 2025-07-29 11:52:03 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-29 11:52:03 +0000 |
| commit | b2d9f17d6ececc5eb53578d57325b6815835ae3c (patch) | |
| tree | 33eea79a18f1b98b937e622d7e6c17f3951ccfae /src | |
| parent | 5043dc9df69322ba7d6bdba3b260dbc1b609dc65 (diff) | |
| parent | ea1e24a989721a1d285d6de913be2be2b5101439 (diff) | |
| download | rust-b2d9f17d6ececc5eb53578d57325b6815835ae3c.tar.gz rust-b2d9f17d6ececc5eb53578d57325b6815835ae3c.zip | |
Merge pull request #20337 from ChayimFriedman2/double-inlay-hints
fix: When displaying a projection into a type parameter that has bounds as `impl Trait`, collect only the bounds of this projection
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/display.rs | 26 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs | 30 |
2 files changed, 43 insertions, 13 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs index b3760e3a382..f0e31ebd020 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs @@ -620,19 +620,19 @@ impl HirDisplay for ProjectionTy { .generic_predicates(id.parent) .iter() .map(|pred| pred.clone().substitute(Interner, &substs)) - .filter(|wc| match wc.skip_binders() { - WhereClause::Implemented(tr) => { - matches!( - tr.self_type_parameter(Interner).kind(Interner), - TyKind::Alias(_) - ) - } - WhereClause::TypeOutlives(t) => { - matches!(t.ty.kind(Interner), TyKind::Alias(_)) - } - // We shouldn't be here if these exist - WhereClause::AliasEq(_) => false, - WhereClause::LifetimeOutlives(_) => false, + .filter(|wc| { + let ty = match wc.skip_binders() { + WhereClause::Implemented(tr) => tr.self_type_parameter(Interner), + WhereClause::TypeOutlives(t) => t.ty.clone(), + // We shouldn't be here if these exist + WhereClause::AliasEq(_) | WhereClause::LifetimeOutlives(_) => { + return false; + } + }; + let TyKind::Alias(AliasTy::Projection(proj)) = ty.kind(Interner) else { + return false; + }; + proj == self }) .collect::<Vec<_>>(); if !bounds.is_empty() { diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs index 19e5509681a..671fddb4363 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs @@ -1065,4 +1065,34 @@ fn bar() { "#, ); } + + #[test] + fn regression_20239() { + check_with_config( + InlayHintsConfig { parameter_hints: true, type_hints: true, ..DISABLED_CONFIG }, + r#" +//- minicore: fn +trait Iterator { + type Item; + fn map<B, F: FnMut(Self::Item) -> B>(self, f: F); +} +trait ToString { + fn to_string(&self); +} + +fn check_tostr_eq<L, R>(left: L, right: R) +where + L: Iterator, + L::Item: ToString, + R: Iterator, + R::Item: ToString, +{ + left.map(|s| s.to_string()); + // ^ impl ToString + right.map(|s| s.to_string()); + // ^ impl ToString +} + "#, + ); + } } |
