diff options
| author | OleStrohm <strohm99@gmail.com> | 2022-09-12 21:02:30 +0100 |
|---|---|---|
| committer | OleStrohm <strohm99@gmail.com> | 2022-09-12 21:02:30 +0100 |
| commit | 177ec82a41a3e42814201e0b718764798a76109f (patch) | |
| tree | 2f1f389b78bb1309007ce12d0811f27e9a227b5b | |
| parent | 5313bd19844d6e485c16b06b60a12dc36449688c (diff) | |
| download | rust-177ec82a41a3e42814201e0b718764798a76109f.tar.gz rust-177ec82a41a3e42814201e0b718764798a76109f.zip | |
Rebased
| -rw-r--r-- | crates/hir-def/src/body/pretty.rs | 12 | ||||
| -rw-r--r-- | crates/hir/src/lib.rs | 7 | ||||
| -rw-r--r-- | crates/ide/src/hover/render.rs | 3 |
3 files changed, 21 insertions, 1 deletions
diff --git a/crates/hir-def/src/body/pretty.rs b/crates/hir-def/src/body/pretty.rs index f2fed954444..9121fb50fd6 100644 --- a/crates/hir-def/src/body/pretty.rs +++ b/crates/hir-def/src/body/pretty.rs @@ -2,6 +2,8 @@ use std::fmt::{self, Write}; +use syntax::ast::HasName; + use crate::{ expr::{Array, BindingAnnotation, Literal, Statement}, 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 }; format!("const {} = ", name) } + DefWithBodyId::VariantId(it) => { + needs_semi = false; + let src = it.parent.child_source(db); + let variant = &src.value[it.local_id]; + let name = match &variant.name() { + Some(name) => name.to_string(), + None => "_".to_string(), + }; + format!("{}", name) + } }; let mut p = Printer { body, buf: header, indent_level: 0, needs_indent: false }; diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 6bcbe62efa8..7d32aef8eb9 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -964,6 +964,12 @@ impl HasVisibility for Enum { } } +impl From<&Variant> for DefWithBodyId { + fn from(&v: &Variant) -> Self { + DefWithBodyId::VariantId(v.into()) + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Variant { pub(crate) parent: Enum, @@ -1179,6 +1185,7 @@ impl DefWithBody { DefWithBody::Function(it) => it.id.into(), DefWithBody::Static(it) => it.id.into(), DefWithBody::Const(it) => it.id.into(), + DefWithBody::Variant(it) => it.into(), } } diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs index 4c429202e6f..8442e101b6f 100644 --- a/crates/ide/src/hover/render.rs +++ b/crates/ide/src/hover/render.rs @@ -3,7 +3,8 @@ use std::fmt::Display; use either::Either; use hir::{ - db::HirDatabase, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay, Semantics, StructKind, TypeInfo, + db::HirDatabase, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay, Semantics, + StructKind, TypeInfo, }; use ide_db::{ base_db::SourceDatabase, |
