aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-01 20:57:39 +0000
committerLukas Wirth <[email protected]>2021-03-04 18:38:02 +0000
commit50e01d2bc7429d718e0783d75458a6a047ee2b70 (patch)
tree5043387dfce7e3fc96777ce5983048f0d2d450e5 /crates/hir_ty/src/lib.rs
parent16a76aa158d0898d6a46d7bba7310150555a69b9 (diff)
Use chalk_ir::AdtId
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index c2a20c480..e77f24e4e 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -27,9 +27,9 @@ use std::{iter, mem, ops::Deref, sync::Arc};
27 27
28use base_db::salsa; 28use base_db::salsa;
29use hir_def::{ 29use hir_def::{
30 builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AdtId, AssocContainerId, 30 builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AssocContainerId, DefWithBodyId,
31 DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, 31 FunctionId, GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId,
32 TypeAliasId, TypeParamId, 32 TypeParamId,
33}; 33};
34use itertools::Itertools; 34use itertools::Itertools;
35 35
@@ -47,7 +47,9 @@ pub use lower::{
47}; 47};
48pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; 48pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
49 49
50pub use chalk_ir::{BoundVar, DebruijnIndex, Mutability, Scalar, TyVariableKind}; 50pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariableKind};
51
52pub(crate) use crate::traits::chalk::Interner;
51 53
52#[derive(Clone, PartialEq, Eq, Debug, Hash)] 54#[derive(Clone, PartialEq, Eq, Debug, Hash)]
53pub enum Lifetime { 55pub enum Lifetime {
@@ -131,7 +133,7 @@ pub enum AliasTy {
131#[derive(Clone, PartialEq, Eq, Debug, Hash)] 133#[derive(Clone, PartialEq, Eq, Debug, Hash)]
132pub enum Ty { 134pub enum Ty {
133 /// Structures, enumerations and unions. 135 /// Structures, enumerations and unions.
134 Adt(AdtId, Substs), 136 Adt(AdtId<Interner>, Substs),
135 137
136 /// Represents an associated item like `Iterator::Item`. This is used 138 /// Represents an associated item like `Iterator::Item`. This is used
137 /// when we have tried to normalize a projection like `T::Item` but 139 /// when we have tried to normalize a projection like `T::Item` but
@@ -602,6 +604,10 @@ impl Ty {
602 Ty::Tuple(0, Substs::empty()) 604 Ty::Tuple(0, Substs::empty())
603 } 605 }
604 606
607 pub fn adt_ty(adt: hir_def::AdtId, substs: Substs) -> Ty {
608 Ty::Adt(AdtId(adt), substs)
609 }
610
605 pub fn fn_ptr(sig: CallableSig) -> Self { 611 pub fn fn_ptr(sig: CallableSig) -> Self {
606 Ty::Function(FnPointer { 612 Ty::Function(FnPointer {
607 num_args: sig.params().len(), 613 num_args: sig.params().len(),
@@ -650,9 +656,9 @@ impl Ty {
650 t 656 t
651 } 657 }
652 658
653 pub fn as_adt(&self) -> Option<(AdtId, &Substs)> { 659 pub fn as_adt(&self) -> Option<(hir_def::AdtId, &Substs)> {
654 match self { 660 match self {
655 Ty::Adt(adt_def, parameters) => Some((*adt_def, parameters)), 661 Ty::Adt(AdtId(adt), parameters) => Some((*adt, parameters)),
656 _ => None, 662 _ => None,
657 } 663 }
658 } 664 }
@@ -666,7 +672,7 @@ impl Ty {
666 672
667 pub fn as_generic_def(&self) -> Option<GenericDefId> { 673 pub fn as_generic_def(&self) -> Option<GenericDefId> {
668 match *self { 674 match *self {
669 Ty::Adt(adt, ..) => Some(adt.into()), 675 Ty::Adt(AdtId(adt), ..) => Some(adt.into()),
670 Ty::FnDef(callable, ..) => Some(callable.into()), 676 Ty::FnDef(callable, ..) => Some(callable.into()),
671 Ty::AssociatedType(type_alias, ..) => Some(type_alias.into()), 677 Ty::AssociatedType(type_alias, ..) => Some(type_alias.into()),
672 Ty::ForeignType(type_alias, ..) => Some(type_alias.into()), 678 Ty::ForeignType(type_alias, ..) => Some(type_alias.into()),