about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-15 20:34:48 +0000
committerbors <bors@rust-lang.org>2023-08-15 20:34:48 +0000
commitb14770934a1cc058ee1721fcf2cd80a39bf21f53 (patch)
treecf5ab1688e5a0df765a75933393830315ce4d5d6
parent54c41250869f2196f7f793e6a5ebac1f6736a61d (diff)
parentfec5ff989025ee01f7659da28e95d0fe0feafa86 (diff)
downloadrust-b14770934a1cc058ee1721fcf2cd80a39bf21f53.tar.gz
rust-b14770934a1cc058ee1721fcf2cd80a39bf21f53.zip
Auto merge of #15463 - ponyii:fix/start-hovering-default-values-of-generic-const, r=HKalbasi
fix: start hovering default values of generic constants

It's just a kind of a postscriptum for [my last PR](https://github.com/rust-lang/rust-analyzer/pull/15179) adding default values of const generics to `hir::ConstParamData`. Here I patch other pieces of code which used to ignore const default values and which I managed to find (you're welcome to show me more)
-rw-r--r--crates/hir/src/display.rs5
-rw-r--r--crates/ide/src/hover/tests.rs45
2 files changed, 49 insertions, 1 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index a701eb01192..ac171026d5d 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -366,6 +366,11 @@ fn write_generic_params(
                     delim(f)?;
                     write!(f, "const {}: ", name.display(f.db.upcast()))?;
                     c.ty.hir_fmt(f)?;
+
+                    if let Some(default) = &c.default {
+                        f.write_str(" = ")?;
+                        write!(f, "{}", default.display(f.db.upcast()))?;
+                    }
                 }
             }
         }
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 541cce8c5bf..d0f9f7b0e16 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -3335,7 +3335,50 @@ struct S$0T<const C: usize = 1, T = Foo>(T);
             ```
 
             ```rust
-            struct ST<const C: usize, T = Foo>
+            struct ST<const C: usize = 1, T = Foo>
+            ```
+        "#]],
+    );
+}
+
+#[test]
+fn const_generic_default_value() {
+    check(
+        r#"
+struct Foo;
+struct S$0T<const C: usize = {40 + 2}, T = Foo>(T);
+"#,
+        expect![[r#"
+            *ST*
+
+            ```rust
+            test
+            ```
+
+            ```rust
+            struct ST<const C: usize = {const}, T = Foo>
+            ```
+        "#]],
+    );
+}
+
+#[test]
+fn const_generic_default_value_2() {
+    check(
+        r#"
+struct Foo;
+const VAL = 1;
+struct S$0T<const C: usize = VAL, T = Foo>(T);
+"#,
+        expect![[r#"
+            *ST*
+
+            ```rust
+            test
+            ```
+
+            ```rust
+            struct ST<const C: usize = VAL, T = Foo>
             ```
         "#]],
     );