mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-27 13:54:20 +00:00
hir_ty: deal with TypeRef::Macro in HirFormatter
This commit is contained in:
parent
cf3b4f1e20
commit
28ef7c20d7
2 changed files with 17 additions and 5 deletions
|
@ -10,7 +10,7 @@ use hir_def::{
|
||||||
resolver::{self, HasResolver, Resolver, TypeNs},
|
resolver::{self, HasResolver, Resolver, TypeNs},
|
||||||
AsMacroCall, FunctionId, TraitId, VariantId,
|
AsMacroCall, FunctionId, TraitId, VariantId,
|
||||||
};
|
};
|
||||||
use hir_expand::{hygiene::Hygiene, name::AsName, ExpansionInfo};
|
use hir_expand::{name::AsName, ExpansionInfo};
|
||||||
use hir_ty::associated_type_shorthand_candidates;
|
use hir_ty::associated_type_shorthand_candidates;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
@ -854,8 +854,7 @@ impl<'a> SemanticsScope<'a> {
|
||||||
/// Resolve a path as-if it was written at the given scope. This is
|
/// Resolve a path as-if it was written at the given scope. This is
|
||||||
/// necessary a heuristic, as it doesn't take hygiene into account.
|
/// necessary a heuristic, as it doesn't take hygiene into account.
|
||||||
pub fn speculative_resolve(&self, path: &ast::Path) -> Option<PathResolution> {
|
pub fn speculative_resolve(&self, path: &ast::Path) -> Option<PathResolution> {
|
||||||
let hygiene = Hygiene::new(self.db.upcast(), self.file_id);
|
let ctx = body::LowerCtx::new(self.db.upcast(), self.file_id);
|
||||||
let ctx = body::LowerCtx::with_hygiene(&hygiene);
|
|
||||||
let path = Path::from_src(path.clone(), &ctx)?;
|
let path = Path::from_src(path.clone(), &ctx)?;
|
||||||
resolve_hir_path(self.db, &self.resolver, &path)
|
resolve_hir_path(self.db, &self.resolver, &path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use std::{
|
||||||
|
|
||||||
use chalk_ir::BoundVar;
|
use chalk_ir::BoundVar;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
|
body,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
find_path,
|
find_path,
|
||||||
generics::TypeParamProvenance,
|
generics::TypeParamProvenance,
|
||||||
|
@ -18,7 +19,7 @@ use hir_def::{
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
AssocContainerId, Lookup, ModuleId, TraitId,
|
AssocContainerId, Lookup, ModuleId, TraitId,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::{hygiene::Hygiene, name::Name};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id,
|
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 ")?;
|
write!(f, "dyn ")?;
|
||||||
f.write_joined(bounds, " + ")?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue