From 8bde16dccefc5bea5c10bc0afe894b0af3279656 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 11 Apr 2025 00:34:13 +0300 Subject: [PATCH] Fix an incorrect `ExpressionStore` that was passed It caused panics everywhere. --- crates/hir/src/display.rs | 12 +++++------ crates/ide/src/hover/tests.rs | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 8885f328db..5c87f2f159 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -39,21 +39,21 @@ impl HirDisplay for Function { // Write container (trait or impl) let container_params = match container { Some(AssocItemContainer::Trait(trait_)) => { - let params = f.db.generic_params(trait_.id.into()); + let (params, params_store) = f.db.generic_params_and_store(trait_.id.into()); if f.show_container_bounds() && !params.is_empty() { write_trait_header(&trait_, f)?; f.write_char('\n')?; - has_disaplayable_predicates(¶ms).then_some(params) + has_disaplayable_predicates(¶ms).then_some((params, params_store)) } else { None } } Some(AssocItemContainer::Impl(impl_)) => { - let params = f.db.generic_params(impl_.id.into()); + let (params, params_store) = f.db.generic_params_and_store(impl_.id.into()); if f.show_container_bounds() && !params.is_empty() { write_impl_header(&impl_, f)?; f.write_char('\n')?; - has_disaplayable_predicates(¶ms).then_some(params) + has_disaplayable_predicates(¶ms).then_some((params, params_store)) } else { None } @@ -169,7 +169,7 @@ impl HirDisplay for Function { // Write where clauses let has_written_where = write_where_clause(GenericDefId::FunctionId(self.id), f)?; - if let Some(container_params) = container_params { + if let Some((container_params, container_params_store)) = container_params { if !has_written_where { f.write_str("\nwhere")?; } @@ -178,7 +178,7 @@ impl HirDisplay for Function { AssocItemContainer::Impl(_) => "impl", }; write!(f, "\n // Bounds from {container_name}:",)?; - write_where_predicates(&container_params, &data.store, f)?; + write_where_predicates(&container_params, &container_params_store, f)?; } Ok(()) } diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 8ed71fd4f6..ab73590734 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -10724,3 +10724,41 @@ impl PublicFlags for NoteDialects { "#]], ); } + +#[test] +fn bounds_from_container_do_not_panic() { + check( + r#" +//- minicore: copy +struct Foo(T); + +impl Foo { + fn foo(&self, _u: U) {} +} + +fn bar(v: &Foo) { + v.$0foo(1u32); +} + "#, + expect![[r#" + *foo* + + ```rust + ra_test_fixture::Foo + ``` + + ```rust + impl Foo + fn foo(&self, _u: U) + where + U: Copy, + // Bounds from impl: + T: Copy, + ``` + + --- + + `T` = `i32`, `U` = `u32` + "#]], + ); +}