Skip to content

Commit 28ef7c2

Browse files
committed
hir_ty: deal with TypeRef::Macro in HirFormatter
1 parent cf3b4f1 commit 28ef7c2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

crates/hir/src/semantics.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use hir_def::{
1010
resolver::{self, HasResolver, Resolver, TypeNs},
1111
AsMacroCall, FunctionId, TraitId, VariantId,
1212
};
13-
use hir_expand::{hygiene::Hygiene, name::AsName, ExpansionInfo};
13+
use hir_expand::{name::AsName, ExpansionInfo};
1414
use hir_ty::associated_type_shorthand_candidates;
1515
use itertools::Itertools;
1616
use rustc_hash::{FxHashMap, FxHashSet};
@@ -854,8 +854,7 @@ impl<'a> SemanticsScope<'a> {
854854
/// Resolve a path as-if it was written at the given scope. This is
855855
/// necessary a heuristic, as it doesn't take hygiene into account.
856856
pub fn speculative_resolve(&self, path: &ast::Path) -> Option<PathResolution> {
857-
let hygiene = Hygiene::new(self.db.upcast(), self.file_id);
858-
let ctx = body::LowerCtx::with_hygiene(&hygiene);
857+
let ctx = body::LowerCtx::new(self.db.upcast(), self.file_id);
859858
let path = Path::from_src(path.clone(), &ctx)?;
860859
resolve_hir_path(self.db, &self.resolver, &path)
861860
}

crates/hir_ty/src/display.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{
99

1010
use chalk_ir::BoundVar;
1111
use hir_def::{
12+
body,
1213
db::DefDatabase,
1314
find_path,
1415
generics::TypeParamProvenance,
@@ -18,7 +19,7 @@ use hir_def::{
1819
visibility::Visibility,
1920
AssocContainerId, Lookup, ModuleId, TraitId,
2021
};
21-
use hir_expand::name::Name;
22+
use hir_expand::{hygiene::Hygiene, name::Name};
2223

2324
use crate::{
2425
const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id,
@@ -997,7 +998,19 @@ impl HirDisplay for TypeRef {
997998
write!(f, "dyn ")?;
998999
f.write_joined(bounds, " + ")?;
9991000
}
1000-
TypeRef::Error | TypeRef::Macro(_) => write!(f, "{{error}}")?,
1001+
TypeRef::Macro(macro_call) => {
1002+
let macro_call = macro_call.to_node(f.db.upcast());
1003+
let ctx = body::LowerCtx::with_hygiene(&Hygiene::new_unhygienic());
1004+
match macro_call.path() {
1005+
Some(path) => match Path::from_src(path, &ctx) {
1006+
Some(path) => path.hir_fmt(f)?,
1007+
None => write!(f, "{{macro}}")?,
1008+
},
1009+
None => write!(f, "{{macro}}")?,
1010+
}
1011+
write!(f, "!(..)")?;
1012+
}
1013+
TypeRef::Error => write!(f, "{{error}}")?,
10011014
}
10021015
Ok(())
10031016
}

0 commit comments

Comments
 (0)