about summary refs log tree commit diff
path: root/src/tools/rust-analyzer
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2025-04-11 00:34:13 +0300
committerChayim Refael Friedman <chayimfr@gmail.com>2025-04-11 00:34:13 +0300
commit405ffce886b9fd343fc90b423141d36fa8e8ae5d (patch)
tree80a1e4c3c512b23cd51440877b38781a9d780c00 /src/tools/rust-analyzer
parent8e18cd614180048d479e6e95b93c1d9998967afc (diff)
downloadrust-405ffce886b9fd343fc90b423141d36fa8e8ae5d.tar.gz
rust-405ffce886b9fd343fc90b423141d36fa8e8ae5d.zip
Fix an incorrect `ExpressionStore` that was passed
It caused panics everywhere.
Diffstat (limited to 'src/tools/rust-analyzer')
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/display.rs12
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/hover/tests.rs38
2 files changed, 44 insertions, 6 deletions
diff --git a/src/tools/rust-analyzer/crates/hir/src/display.rs b/src/tools/rust-analyzer/crates/hir/src/display.rs
index 8885f328dbd..5c87f2f1590 100644
--- a/src/tools/rust-analyzer/crates/hir/src/display.rs
+++ b/src/tools/rust-analyzer/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(&params).then_some(params)
+                    has_disaplayable_predicates(&params).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(&params).then_some(params)
+                    has_disaplayable_predicates(&params).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/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
index 8ed71fd4f6a..ab735907344 100644
--- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
+++ b/src/tools/rust-analyzer/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>(T);
+
+impl<T: Copy> Foo<T> {
+    fn foo<U: Copy>(&self, _u: U) {}
+}
+
+fn bar(v: &Foo<i32>) {
+    v.$0foo(1u32);
+}
+    "#,
+        expect![[r#"
+            *foo*
+
+            ```rust
+            ra_test_fixture::Foo
+            ```
+
+            ```rust
+            impl<T> Foo<T>
+            fn foo<U>(&self, _u: U)
+            where
+                U: Copy,
+                // Bounds from impl:
+                T: Copy,
+            ```
+
+            ---
+
+            `T` = `i32`, `U` = `u32`
+        "#]],
+    );
+}