Skip to content

Commit e57f184

Browse files
authored
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
2 parents c12ec2e + 9b8c5cf commit e57f184

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

crates/hir-ty/src/display.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -620,19 +620,19 @@ impl HirDisplay for ProjectionTy {
620620
.generic_predicates(id.parent)
621621
.iter()
622622
.map(|pred| pred.clone().substitute(Interner, &substs))
623-
.filter(|wc| match wc.skip_binders() {
624-
WhereClause::Implemented(tr) => {
625-
matches!(
626-
tr.self_type_parameter(Interner).kind(Interner),
627-
TyKind::Alias(_)
628-
)
629-
}
630-
WhereClause::TypeOutlives(t) => {
631-
matches!(t.ty.kind(Interner), TyKind::Alias(_))
632-
}
633-
// We shouldn't be here if these exist
634-
WhereClause::AliasEq(_) => false,
635-
WhereClause::LifetimeOutlives(_) => false,
623+
.filter(|wc| {
624+
let ty = match wc.skip_binders() {
625+
WhereClause::Implemented(tr) => tr.self_type_parameter(Interner),
626+
WhereClause::TypeOutlives(t) => t.ty.clone(),
627+
// We shouldn't be here if these exist
628+
WhereClause::AliasEq(_) | WhereClause::LifetimeOutlives(_) => {
629+
return false;
630+
}
631+
};
632+
let TyKind::Alias(AliasTy::Projection(proj)) = ty.kind(Interner) else {
633+
return false;
634+
};
635+
proj == self
636636
})
637637
.collect::<Vec<_>>();
638638
if !bounds.is_empty() {

crates/ide/src/inlay_hints.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,4 +1065,34 @@ fn bar() {
10651065
"#,
10661066
);
10671067
}
1068+
1069+
#[test]
1070+
fn regression_20239() {
1071+
check_with_config(
1072+
InlayHintsConfig { parameter_hints: true, type_hints: true, ..DISABLED_CONFIG },
1073+
r#"
1074+
//- minicore: fn
1075+
trait Iterator {
1076+
type Item;
1077+
fn map<B, F: FnMut(Self::Item) -> B>(self, f: F);
1078+
}
1079+
trait ToString {
1080+
fn to_string(&self);
1081+
}
1082+
1083+
fn check_tostr_eq<L, R>(left: L, right: R)
1084+
where
1085+
L: Iterator,
1086+
L::Item: ToString,
1087+
R: Iterator,
1088+
R::Item: ToString,
1089+
{
1090+
left.map(|s| s.to_string());
1091+
// ^ impl ToString
1092+
right.map(|s| s.to_string());
1093+
// ^ impl ToString
1094+
}
1095+
"#,
1096+
);
1097+
}
10681098
}

0 commit comments

Comments
 (0)