Repository: rust-analyzer/rust-analyzer (rust)

Issue:
Value of string constant is not displayed correctly when hovered over
**rust-analyzer version**: `rust-analyzer 4e72700e3 2022-02-28 stable`

**rustc version**: `rustc 1.59.0 (9d1b2106e 2022-02-23)`

**relevant settings**: None

<img width="415" src="https://user-images.githubusercontent.com/51911626/155995100-50505f93-9d6b-4ea8-af78-f3dc8a725352.png">

The definition incorrectly shows that `HELLO_WORLD` is an empty string.

Pull request description:
fix: lower string literals with actual value instead of default
Fixes #11582. Some questions below in the code review section.

Patch:
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index 06ad7ce4cd..085eea7fbd 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -923,7 +923,10 @@ impl From<ast::LiteralKind> for Literal {
                 let text = bs.value().map(Box::from).unwrap_or_else(Default::default);
                 Literal::ByteString(text)
             }
-            LiteralKind::String(_) => Literal::String(Default::default()),
+            LiteralKind::String(s) => {
+                let text = s.value().map(Box::from).unwrap_or_else(Default::default);
+                Literal::String(text)
+            }
             LiteralKind::Byte => Literal::Uint(Default::default(), Some(BuiltinUint::U8)),
             LiteralKind::Bool(val) => Literal::Bool(val),
             LiteralKind::Char => Literal::Char(Default::default()),


Test patch:
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index df0ca941c9..d74666b514 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -3487,6 +3487,27 @@ const FOO$0: usize = 1 << 100;
 
             ---
 
+            This is a doc
+        "#]],
+    );
+    check(
+        r#"
+/// This is a doc
+const FOO$0: &str = "bar";
+"#,
+        expect![[r#"
+            *FOO*
+
+            ```rust
+            test
+            ```
+
+            ```rust
+            const FOO: &str = "bar"
+            ```
+
+            ---
+
             This is a doc
         "#]],
     );