mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Move ProjectionTy methods to extension trait
This commit is contained in:
parent
8c96a7d81e
commit
788533d380
7 changed files with 43 additions and 32 deletions
|
@ -1,6 +1,11 @@
|
|||
//! Various extensions traits for Chalk types.
|
||||
|
||||
use crate::{Interner, Ty, TyKind};
|
||||
use hir_def::{AssocContainerId, Lookup, TraitId};
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase, from_assoc_type_id, to_chalk_trait_id, Interner, ProjectionTy, TraitRef, Ty,
|
||||
TyKind,
|
||||
};
|
||||
|
||||
pub trait TyExt {
|
||||
fn is_unit(&self) -> bool;
|
||||
|
@ -11,3 +16,24 @@ impl TyExt for Ty {
|
|||
matches!(self.kind(&Interner), TyKind::Tuple(0, _))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ProjectionTyExt {
|
||||
fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef;
|
||||
fn trait_(&self, db: &dyn HirDatabase) -> TraitId;
|
||||
}
|
||||
|
||||
impl ProjectionTyExt for ProjectionTy {
|
||||
fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef {
|
||||
TraitRef {
|
||||
trait_id: to_chalk_trait_id(self.trait_(db)),
|
||||
substitution: self.substitution.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
|
||||
match from_assoc_type_id(self.associated_ty_id).lookup(db.upcast()).container {
|
||||
AssocContainerId::TraitId(it) => it,
|
||||
_ => panic!("projection ty without parent trait"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue