]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide/src/hover/render.rs
Merge #11194
[rust.git] / crates / ide / src / hover / render.rs
index b0edec56ff1a3f04fe5570c0d71b0272e3c189b7..d29833a65b306ed3fe1bde8e72c6d86d6abc1add 100644 (file)
@@ -360,7 +360,13 @@ pub(super) fn definition(
         Definition::Function(it) => label_and_docs(db, it),
         Definition::Adt(it) => label_and_docs(db, it),
         Definition::Variant(it) => label_and_docs(db, it),
-        Definition::Const(it) => label_value_and_docs(db, it, |it| it.value(db)),
+        Definition::Const(it) => label_value_and_docs(db, it, |it| {
+            let body = it.eval(db);
+            match body {
+                Ok(x) => Some(format!("{}", x)),
+                Err(_) => it.value(db).map(|x| format!("{}", x)),
+            }
+        }),
         Definition::Static(it) => label_value_and_docs(db, it, |it| it.value(db)),
         Definition::Trait(it) => label_and_docs(db, it),
         Definition::TypeAlias(it) => label_and_docs(db, it),
@@ -387,7 +393,10 @@ fn render_builtin_attr(db: &RootDatabase, attr: hir::BuiltinAttr) -> Option<Mark
     let name = attr.name(db);
     let desc = format!("#[{}]", name);
 
-    let AttributeTemplate { word, list, name_value_str } = attr.template(db);
+    let AttributeTemplate { word, list, name_value_str } = match attr.template(db) {
+        Some(template) => template,
+        None => return Some(Markup::fenced_block(&attr.name(db))),
+    };
     let mut docs = "Valid forms are:".to_owned();
     if word {
         format_to!(docs, "\n - #\\[{}]", name);
@@ -420,7 +429,7 @@ fn label_value_and_docs<D, E, V>(
     E: Fn(&D) -> Option<V>,
     V: Display,
 {
-    let label = if let Some(value) = (value_extractor)(&def) {
+    let label = if let Some(value) = value_extractor(&def) {
         format!("{} = {}", def.display(db), value)
     } else {
         def.display(db).to_string()