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),
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);
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()