Skip to content

Commit 177ec82

Browse files
committed
Rebased
1 parent 5313bd1 commit 177ec82

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

crates/hir-def/src/body/pretty.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use std::fmt::{self, Write};
44

5+
use syntax::ast::HasName;
6+
57
use crate::{
68
expr::{Array, BindingAnnotation, Literal, Statement},
79
pretty::{print_generic_args, print_path, print_type_ref},
@@ -32,6 +34,16 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
3234
};
3335
format!("const {} = ", name)
3436
}
37+
DefWithBodyId::VariantId(it) => {
38+
needs_semi = false;
39+
let src = it.parent.child_source(db);
40+
let variant = &src.value[it.local_id];
41+
let name = match &variant.name() {
42+
Some(name) => name.to_string(),
43+
None => "_".to_string(),
44+
};
45+
format!("{}", name)
46+
}
3547
};
3648

3749
let mut p = Printer { body, buf: header, indent_level: 0, needs_indent: false };

crates/hir/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,12 @@ impl HasVisibility for Enum {
964964
}
965965
}
966966

967+
impl From<&Variant> for DefWithBodyId {
968+
fn from(&v: &Variant) -> Self {
969+
DefWithBodyId::VariantId(v.into())
970+
}
971+
}
972+
967973
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
968974
pub struct Variant {
969975
pub(crate) parent: Enum,
@@ -1179,6 +1185,7 @@ impl DefWithBody {
11791185
DefWithBody::Function(it) => it.id.into(),
11801186
DefWithBody::Static(it) => it.id.into(),
11811187
DefWithBody::Const(it) => it.id.into(),
1188+
DefWithBody::Variant(it) => it.into(),
11821189
}
11831190
}
11841191

crates/ide/src/hover/render.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::fmt::Display;
33

44
use either::Either;
55
use hir::{
6-
db::HirDatabase, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay, Semantics, StructKind, TypeInfo,
6+
db::HirDatabase, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay, Semantics,
7+
StructKind, TypeInfo,
78
};
89
use ide_db::{
910
base_db::SourceDatabase,

0 commit comments

Comments
 (0)