ide: hover omits unnamed where preds
This commit is contained in:
parent
14dff25107
commit
7cbc6ae920
@ -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)
|
||||
{
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user