10817: ide: hover omits unnamed where preds r=Veykril a=jhgg

fixes #10800

Co-authored-by: Jake Heinz <jh@discordapp.com>
This commit is contained in:
bors[bot] 2021-11-20 12:01:22 +00:00 committed by GitHub
commit 5f5c84d921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 1 deletions

View File

@ -325,7 +325,21 @@ fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), H
fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
let params = f.db.generic_params(def);
if params.where_predicates.is_empty() {
// unnamed type targets are displayed inline with the argument itself, e.g. `f: impl Y`.
let is_unnamed_type_target = |target: &WherePredicateTypeTarget| match target {
WherePredicateTypeTarget::TypeRef(_) => false,
WherePredicateTypeTarget::TypeParam(id) => params.types[*id].name.is_none(),
};
let has_displayable_predicate = params
.where_predicates
.iter()
.any(|pred| {
!matches!(pred, WherePredicate::TypeBound { target, .. } if is_unnamed_type_target(target))
});
if !has_displayable_predicate {
return Ok(());
}
@ -348,6 +362,7 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir
};
match pred {
WherePredicate::TypeBound { target, .. } if is_unnamed_type_target(target) => {}
WherePredicate::TypeBound { target, bound } => {
if matches!(prev_pred, Some(WherePredicate::TypeBound { target: target_, .. }) if target_ == target)
{

View File

@ -340,6 +340,48 @@ fn main() { m::f$0oo(); }
);
}
#[test]
fn hover_omits_unnamed_where_preds() {
check(
r#"
pub fn foo(bar: impl T) { }
fn main() { fo$0o(); }
"#,
expect![[r#"
*foo*
```rust
test
```
```rust
pub fn foo(bar: impl T)
```
"#]],
);
check(
r#"
pub fn foo<V: AsRef<str>>(bar: impl T, baz: V) { }
fn main() { fo$0o(); }
"#,
expect![[r#"
*foo*
```rust
test
```
```rust
pub fn foo<V>(bar: impl T, baz: V)
where
V: AsRef<str>,
```
"#]],
);
}
#[test]
fn hover_shows_fn_signature_with_type_params() {
check(