mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Use chalk_ir::AssocTypeId
This commit is contained in:
parent
dfafcd926a
commit
19664e276a
10 changed files with 87 additions and 76 deletions
|
@ -11,9 +11,9 @@ use hir_def::{
|
|||
use hir_expand::name::Name;
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase, from_foreign_def_id, primitive, utils::generics, AdtId, AliasTy,
|
||||
CallableDefId, CallableSig, GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy,
|
||||
OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind,
|
||||
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, primitive, to_assoc_type_id,
|
||||
utils::generics, AdtId, AliasTy, CallableDefId, CallableSig, GenericPredicate, Interner,
|
||||
Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind,
|
||||
};
|
||||
|
||||
pub struct HirFormatter<'a> {
|
||||
|
@ -256,7 +256,7 @@ impl HirDisplay for ProjectionTy {
|
|||
f.write_joined(&self.parameters[1..], ", ")?;
|
||||
write!(f, ">")?;
|
||||
}
|
||||
write!(f, ">::{}", f.db.type_alias_data(self.associated_ty).name)?;
|
||||
write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty)).name)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -467,13 +467,14 @@ impl HirDisplay for Ty {
|
|||
}
|
||||
}
|
||||
}
|
||||
TyKind::AssociatedType(type_alias, parameters) => {
|
||||
TyKind::AssociatedType(assoc_type_id, parameters) => {
|
||||
let type_alias = from_assoc_type_id(*assoc_type_id);
|
||||
let trait_ = match type_alias.lookup(f.db.upcast()).container {
|
||||
AssocContainerId::TraitId(it) => it,
|
||||
_ => panic!("not an associated type"),
|
||||
};
|
||||
let trait_ = f.db.trait_data(trait_);
|
||||
let type_alias_data = f.db.type_alias_data(*type_alias);
|
||||
let type_alias_data = f.db.type_alias_data(type_alias);
|
||||
|
||||
// Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
|
||||
if f.display_target.is_test() {
|
||||
|
@ -484,8 +485,10 @@ impl HirDisplay for Ty {
|
|||
write!(f, ">")?;
|
||||
}
|
||||
} else {
|
||||
let projection_ty =
|
||||
ProjectionTy { associated_ty: *type_alias, parameters: parameters.clone() };
|
||||
let projection_ty = ProjectionTy {
|
||||
associated_ty: to_assoc_type_id(type_alias),
|
||||
parameters: parameters.clone(),
|
||||
};
|
||||
|
||||
projection_ty.hir_fmt(f)?;
|
||||
}
|
||||
|
@ -697,7 +700,9 @@ fn write_bounds_like_dyn_trait(
|
|||
write!(f, "<")?;
|
||||
angle_open = true;
|
||||
}
|
||||
let type_alias = f.db.type_alias_data(projection_pred.projection_ty.associated_ty);
|
||||
let type_alias = f.db.type_alias_data(from_assoc_type_id(
|
||||
projection_pred.projection_ty.associated_ty,
|
||||
));
|
||||
write!(f, "{} = ", type_alias.name)?;
|
||||
projection_pred.ty.hir_fmt(f)?;
|
||||
}
|
||||
|
@ -768,7 +773,10 @@ impl HirDisplay for GenericPredicate {
|
|||
write!(
|
||||
f,
|
||||
">::{} = ",
|
||||
f.db.type_alias_data(projection_pred.projection_ty.associated_ty).name,
|
||||
f.db.type_alias_data(from_assoc_type_id(
|
||||
projection_pred.projection_ty.associated_ty
|
||||
))
|
||||
.name,
|
||||
)?;
|
||||
projection_pred.ty.hir_fmt(f)?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue