Merge pull request #21226 from benodiwal/fix/impl-display-trait-generic-args
Some checks are pending
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run

fix: fixed Impl display to show trait generic args
This commit is contained in:
Chayim Refael Friedman 2025-12-08 21:26:46 +00:00 committed by GitHub
commit e1b11fe83e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 62 additions and 3 deletions

View file

@ -192,9 +192,11 @@ fn write_impl_header<'db>(impl_: &Impl, f: &mut HirFormatter<'_, 'db>) -> Result
let def_id = GenericDefId::ImplId(impl_.id);
write_generic_params(def_id, f)?;
if let Some(trait_) = impl_.trait_(db) {
let trait_data = db.trait_signature(trait_.id);
write!(f, " {} for", trait_data.name.display(db, f.edition()))?;
let impl_data = db.impl_signature(impl_.id);
if let Some(target_trait) = &impl_data.target_trait {
f.write_char(' ')?;
hir_display_with_store(&impl_data.store[target_trait.path], &impl_data.store).hir_fmt(f)?;
f.write_str(" for")?;
}
f.write_char(' ')?;

View file

@ -11169,3 +11169,60 @@ fn foo() {
"#]],
);
}
#[test]
fn hover_trait_impl_shows_generic_args() {
// Single generic arg
check(
r#"
trait Foo<T> {
fn foo(&self) {}
}
impl<T> Foo<()> for T {
fn fo$0o(&self) {}
}
fn bar() {
().foo();
}
"#,
expect![[r#"
*foo*
```rust
ra_test_fixture
```
```rust
impl<T> Foo<()> for T
fn foo(&self)
```
"#]],
);
// Multiple generic args
check(
r#"
trait Foo<A, B> {
fn foo(&self) {}
}
impl<T> Foo<i32, u64> for T {
fn fo$0o(&self) {}
}
"#,
expect![[r#"
*foo*
```rust
ra_test_fixture
```
```rust
impl<T> Foo<i32, u64> for T
fn foo(&self)
```
"#]],
);
}