From 01df4c04d12be89d53addca2885221419e56bf31 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 21 May 2021 23:45:09 +0200 Subject: impl Display for AttrInput/ImportAlias --- crates/hir_def/src/attr.rs | 11 ++++++++++- crates/hir_def/src/path.rs | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index aadd4e44a..89a1ea770 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs @@ -2,7 +2,7 @@ use std::{ convert::{TryFrom, TryInto}, - ops, + fmt, ops, sync::Arc, }; @@ -648,6 +648,15 @@ pub enum AttrInput { TokenTree(Subtree), } +impl fmt::Display for AttrInput { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + AttrInput::Literal(lit) => write!(f, " = \"{}\"", lit.escape_debug()), + AttrInput::TokenTree(subtree) => subtree.fmt(f), + } + } +} + impl Attr { fn from_src( db: &dyn DefDatabase, diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index a43441b1c..9b8873fd2 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs @@ -46,6 +46,15 @@ pub enum ImportAlias { Alias(Name), } +impl Display for ImportAlias { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ImportAlias::Underscore => f.write_str("_"), + ImportAlias::Alias(name) => f.write_str(&name.to_string()), + } + } +} + impl ModPath { pub fn from_src(db: &dyn DefDatabase, path: ast::Path, hygiene: &Hygiene) -> Option { let ctx = LowerCtx::with_hygiene(db, hygiene); -- cgit v1.2.3