-//! FIXME: write short doc here
+//! The `HirDisplay` trait, which serves two purposes: Turning various bits from
+//! HIR back into source code, and just displaying them for debugging/testing
+//! purposes.
use std::{
array,
use chalk_ir::BoundVar;
use hir_def::{
+ body,
db::DefDatabase,
find_path,
generics::TypeParamProvenance,
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,
- from_placeholder_idx, lt_from_placeholder_idx, primitive, subst_prefix, to_assoc_type_id,
- traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId,
- CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime,
- LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt,
- QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
+ from_placeholder_idx, lt_from_placeholder_idx, mapping::from_chalk, primitive, subst_prefix,
+ to_assoc_type_id, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, Const,
+ ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData,
+ LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, QuantifiedWhereClause,
+ Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
};
pub struct HirFormatter<'a> {
let param_data = &generics.params.consts[id.local_id];
write!(f, "{}", param_data.name)
}
- ConstValue::Concrete(_) => write!(f, "_"),
+ ConstValue::Concrete(c) => write!(f, "{}", c.interned),
}
}
}
write!(f, "{}", mutability)?;
inner.hir_fmt(f)?;
}
- TypeRef::Array(inner) => {
+ TypeRef::Array(inner, len) => {
write!(f, "[")?;
inner.hir_fmt(f)?;
- // FIXME: Array length?
- write!(f, "; _]")?;
+ write!(f, "; {}]", len)?;
}
TypeRef::Slice(inner) => {
write!(f, "[")?;
write!(f, "dyn ")?;
f.write_joined(bounds, " + ")?;
}
+ TypeRef::Macro(macro_call) => {
+ let macro_call = macro_call.to_node(f.db.upcast());
+ let ctx = body::LowerCtx::with_hygiene(f.db.upcast(), &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(())