From 28ef7c20d79803403be58eeffa18ab1fb21e261c Mon Sep 17 00:00:00 2001 From: cynecx Date: Mon, 12 Apr 2021 16:24:48 +0200 Subject: hir_ty: deal with TypeRef::Macro in HirFormatter --- crates/hir_ty/src/display.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 63bcb0640..4fb7d9cf2 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -9,6 +9,7 @@ use std::{ use chalk_ir::BoundVar; use hir_def::{ + body, db::DefDatabase, find_path, generics::TypeParamProvenance, @@ -18,7 +19,7 @@ use hir_def::{ visibility::Visibility, AssocContainerId, Lookup, ModuleId, TraitId, }; -use hir_expand::name::Name; +use hir_expand::{hygiene::Hygiene, name::Name}; use crate::{ const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id, @@ -997,7 +998,19 @@ impl HirDisplay for TypeRef { write!(f, "dyn ")?; f.write_joined(bounds, " + ")?; } - TypeRef::Error | TypeRef::Macro(_) => write!(f, "{{error}}")?, + TypeRef::Macro(macro_call) => { + let macro_call = macro_call.to_node(f.db.upcast()); + let ctx = body::LowerCtx::with_hygiene(&Hygiene::new_unhygienic()); + match macro_call.path() { + Some(path) => match Path::from_src(path, &ctx) { + Some(path) => path.hir_fmt(f)?, + None => write!(f, "{{macro}}")?, + }, + None => write!(f, "{{macro}}")?, + } + write!(f, "!(..)")?; + } + TypeRef::Error => write!(f, "{{error}}")?, } Ok(()) } -- cgit v1.2.3