aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-04-06 10:45:41 +0100
committerLukas Wirth <[email protected]>2021-04-06 10:45:41 +0100
commit9fbba7bc45ec6bea9468931d9d9fdd0141826f0a (patch)
tree266da1eafcd60457fa99cc422a415e27992c08d7 /crates/hir_ty/src/lib.rs
parent047b5313013383fc4fafaef6d6d8d6a64549e3cb (diff)
Add chalk_ir::Const to TyKind::Array
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index bccc73449..a2a5bcc07 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -30,12 +30,13 @@ mod test_db;
30 30
31use std::sync::Arc; 31use std::sync::Arc;
32 32
33use chalk_ir::UintTy;
33use itertools::Itertools; 34use itertools::Itertools;
34 35
35use base_db::salsa; 36use base_db::salsa;
36use hir_def::{ 37use hir_def::{
37 expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, GenericDefId, HasModule, 38 expr::ExprId, type_ref::Rawness, AssocContainerId, ConstParamId, FunctionId, GenericDefId,
38 LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId, 39 HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId,
39}; 40};
40 41
41use crate::{db::HirDatabase, display::HirDisplay, utils::generics}; 42use crate::{db::HirDatabase, display::HirDisplay, utils::generics};
@@ -71,6 +72,11 @@ pub type Lifetime = chalk_ir::Lifetime<Interner>;
71pub type LifetimeData = chalk_ir::LifetimeData<Interner>; 72pub type LifetimeData = chalk_ir::LifetimeData<Interner>;
72pub type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>; 73pub type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>;
73 74
75pub type Const = chalk_ir::Const<Interner>;
76pub type ConstData = chalk_ir::ConstData<Interner>;
77pub type ConstValue = chalk_ir::ConstValue<Interner>;
78pub type ConcreteConst = chalk_ir::ConcreteConst<Interner>;
79
74pub type ChalkTraitId = chalk_ir::TraitId<Interner>; 80pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
75 81
76pub type FnSig = chalk_ir::FnSig<Interner>; 82pub type FnSig = chalk_ir::FnSig<Interner>;
@@ -227,7 +233,9 @@ impl Ty {
227 pub fn equals_ctor(&self, other: &Ty) -> bool { 233 pub fn equals_ctor(&self, other: &Ty) -> bool {
228 match (self.kind(&Interner), other.kind(&Interner)) { 234 match (self.kind(&Interner), other.kind(&Interner)) {
229 (TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2, 235 (TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
230 (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true, 236 (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => {
237 true
238 }
231 (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2, 239 (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
232 (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2, 240 (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2,
233 (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => { 241 (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => {
@@ -488,6 +496,12 @@ pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> L
488 db.lookup_intern_lifetime_param_id(interned_id) 496 db.lookup_intern_lifetime_param_id(interned_id)
489} 497}
490 498
499pub fn const_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> ConstParamId {
500 assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
501 let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
502 db.lookup_intern_const_param_id(interned_id)
503}
504
491pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId { 505pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
492 chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id)) 506 chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
493} 507}
@@ -499,3 +513,12 @@ pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId {
499pub fn static_lifetime() -> Lifetime { 513pub fn static_lifetime() -> Lifetime {
500 LifetimeData::Static.intern(&Interner) 514 LifetimeData::Static.intern(&Interner)
501} 515}
516
517pub fn dummy_usize_const() -> Const {
518 let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner);
519 chalk_ir::ConstData {
520 ty: usize_ty,
521 value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }),
522 }
523 .intern(&Interner)
524}