From 89a19f57f8d094826bf68641c4be76a77a7cddcf Mon Sep 17 00:00:00 2001 From: Tianyi Song <42670338+tysg@users.noreply.github.com> Date: Tue, 1 Mar 2022 15:44:53 +0800 Subject: [PATCH] Lower string literals with real val, not default --- crates/hir_def/src/body/lower.rs | 5 ++++- crates/ide/src/hover/tests.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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 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()), 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 "#]], );