aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
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
parent16a76aa158d0898d6a46d7bba7310150555a69b9 (diff)
Use chalk_ir::AdtId
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/diagnostics/expr.rs14
-rw-r--r--crates/hir_ty/src/diagnostics/match_check.rs6
-rw-r--r--crates/hir_ty/src/display.rs21
-rw-r--r--crates/hir_ty/src/infer/expr.rs24
-rw-r--r--crates/hir_ty/src/infer/pat.rs2
-rw-r--r--crates/hir_ty/src/lib.rs22
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/hir_ty/src/method_resolution.rs14
-rw-r--r--crates/hir_ty/src/traits/chalk.rs14
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs16
10 files changed, 65 insertions, 70 deletions
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs
index 66a88e2b6..2751cd304 100644
--- a/crates/hir_ty/src/diagnostics/expr.rs
+++ b/crates/hir_ty/src/diagnostics/expr.rs
@@ -2,9 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{ 5use hir_def::{expr::Statement, path::path, resolver::HasResolver, AssocItemId, DefWithBodyId};
6 expr::Statement, path::path, resolver::HasResolver, AdtId, AssocItemId, DefWithBodyId,
7};
8use hir_expand::{diagnostics::DiagnosticSink, name}; 6use hir_expand::{diagnostics::DiagnosticSink, name};
9use rustc_hash::FxHashSet; 7use rustc_hash::FxHashSet;
10use syntax::{ast, AstPtr}; 8use syntax::{ast, AstPtr};
@@ -17,7 +15,7 @@ use crate::{
17 MissingPatFields, RemoveThisSemicolon, 15 MissingPatFields, RemoveThisSemicolon,
18 }, 16 },
19 utils::variant_data, 17 utils::variant_data,
20 InferenceResult, Ty, 18 AdtId, InferenceResult, Ty,
21}; 19};
22 20
23pub(crate) use hir_def::{ 21pub(crate) use hir_def::{
@@ -382,10 +380,14 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
382 }; 380 };
383 381
384 let (params, required) = match mismatch.expected { 382 let (params, required) = match mismatch.expected {
385 Ty::Adt(AdtId::EnumId(enum_id), ref parameters) if enum_id == core_result_enum => { 383 Ty::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters)
384 if enum_id == core_result_enum =>
385 {
386 (parameters, "Ok".to_string()) 386 (parameters, "Ok".to_string())
387 } 387 }
388 Ty::Adt(AdtId::EnumId(enum_id), ref parameters) if enum_id == core_option_enum => { 388 Ty::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ref parameters)
389 if enum_id == core_option_enum =>
390 {
389 (parameters, "Some".to_string()) 391 (parameters, "Some".to_string())
390 } 392 }
391 _ => return, 393 _ => return,
diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs
index 86fee0050..04d39c571 100644
--- a/crates/hir_ty/src/diagnostics/match_check.rs
+++ b/crates/hir_ty/src/diagnostics/match_check.rs
@@ -222,12 +222,12 @@ use hir_def::{
222 adt::VariantData, 222 adt::VariantData,
223 body::Body, 223 body::Body,
224 expr::{Expr, Literal, Pat, PatId}, 224 expr::{Expr, Literal, Pat, PatId},
225 AdtId, EnumVariantId, StructId, VariantId, 225 EnumVariantId, StructId, VariantId,
226}; 226};
227use la_arena::Idx; 227use la_arena::Idx;
228use smallvec::{smallvec, SmallVec}; 228use smallvec::{smallvec, SmallVec};
229 229
230use crate::{db::HirDatabase, InferenceResult, Ty}; 230use crate::{db::HirDatabase, AdtId, InferenceResult, Ty};
231 231
232#[derive(Debug, Clone, Copy)] 232#[derive(Debug, Clone, Copy)]
233/// Either a pattern from the source code being analyzed, represented as 233/// Either a pattern from the source code being analyzed, represented as
@@ -627,7 +627,7 @@ pub(super) fn is_useful(
627 // - `!` type 627 // - `!` type
628 // In those cases, no match arm is useful. 628 // In those cases, no match arm is useful.
629 match cx.infer[cx.match_expr].strip_references() { 629 match cx.infer[cx.match_expr].strip_references() {
630 Ty::Adt(AdtId::EnumId(enum_id), ..) => { 630 Ty::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), ..) => {
631 if cx.db.enum_data(*enum_id).variants.is_empty() { 631 if cx.db.enum_data(*enum_id).variants.is_empty() {
632 return Ok(Usefulness::NotUseful); 632 return Ok(Usefulness::NotUseful);
633 } 633 }
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index d4a8b48e6..a0882a2a1 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -2,19 +2,20 @@
2 2
3use std::{borrow::Cow, fmt}; 3use std::{borrow::Cow, fmt};
4 4
5use crate::{
6 db::HirDatabase, primitive, utils::generics, AliasTy, CallableDefId, CallableSig,
7 GenericPredicate, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs,
8 TraitRef, Ty,
9};
10use arrayvec::ArrayVec; 5use arrayvec::ArrayVec;
11use chalk_ir::Mutability; 6use chalk_ir::Mutability;
12use hir_def::{ 7use hir_def::{
13 db::DefDatabase, find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, 8 db::DefDatabase, find_path, generics::TypeParamProvenance, item_scope::ItemInNs,
14 AssocContainerId, HasModule, Lookup, ModuleId, TraitId, 9 AssocContainerId, HasModule, Lookup, ModuleId, TraitId,
15}; 10};
16use hir_expand::name::Name; 11use hir_expand::name::Name;
17 12
13use crate::{
14 db::HirDatabase, primitive, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig,
15 GenericPredicate, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs,
16 TraitRef, Ty,
17};
18
18pub struct HirFormatter<'a> { 19pub struct HirFormatter<'a> {
19 pub db: &'a dyn HirDatabase, 20 pub db: &'a dyn HirDatabase,
20 fmt: &'a mut dyn fmt::Write, 21 fmt: &'a mut dyn fmt::Write,
@@ -400,13 +401,13 @@ impl HirDisplay for Ty {
400 write!(f, " -> {}", ret_display)?; 401 write!(f, " -> {}", ret_display)?;
401 } 402 }
402 } 403 }
403 Ty::Adt(def_id, parameters) => { 404 Ty::Adt(AdtId(def_id), parameters) => {
404 match f.display_target { 405 match f.display_target {
405 DisplayTarget::Diagnostics | DisplayTarget::Test => { 406 DisplayTarget::Diagnostics | DisplayTarget::Test => {
406 let name = match *def_id { 407 let name = match *def_id {
407 AdtId::StructId(it) => f.db.struct_data(it).name.clone(), 408 hir_def::AdtId::StructId(it) => f.db.struct_data(it).name.clone(),
408 AdtId::UnionId(it) => f.db.union_data(it).name.clone(), 409 hir_def::AdtId::UnionId(it) => f.db.union_data(it).name.clone(),
409 AdtId::EnumId(it) => f.db.enum_data(it).name.clone(), 410 hir_def::AdtId::EnumId(it) => f.db.enum_data(it).name.clone(),
410 }; 411 };
411 write!(f, "{}", name)?; 412 write!(f, "{}", name)?;
412 } 413 }
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index cf1f1038a..ec2c13154 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -8,7 +8,7 @@ use hir_def::{
8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
9 path::{GenericArg, GenericArgs}, 9 path::{GenericArg, GenericArgs},
10 resolver::resolver_for_expr, 10 resolver::resolver_for_expr,
11 AdtId, AssocContainerId, FieldId, Lookup, 11 AssocContainerId, FieldId, Lookup,
12}; 12};
13use hir_expand::name::{name, Name}; 13use hir_expand::name::{name, Name};
14use syntax::ast::RangeOp; 14use syntax::ast::RangeOp;
@@ -21,8 +21,8 @@ use crate::{
21 primitive::{self, UintTy}, 21 primitive::{self, UintTy},
22 traits::{FnTrait, InEnvironment}, 22 traits::{FnTrait, InEnvironment},
23 utils::{generics, variant_data, Generics}, 23 utils::{generics, variant_data, Generics},
24 Binders, CallableDefId, FnPointer, FnSig, Obligation, OpaqueTyId, Rawness, Scalar, Substs, 24 AdtId, Binders, CallableDefId, FnPointer, FnSig, Obligation, OpaqueTyId, Rawness, Scalar,
25 TraitRef, Ty, 25 Substs, TraitRef, Ty,
26}; 26};
27 27
28use super::{ 28use super::{
@@ -429,14 +429,14 @@ impl<'a> InferenceContext<'a> {
429 Ty::Tuple(_, substs) => { 429 Ty::Tuple(_, substs) => {
430 name.as_tuple_index().and_then(|idx| substs.0.get(idx).cloned()) 430 name.as_tuple_index().and_then(|idx| substs.0.get(idx).cloned())
431 } 431 }
432 Ty::Adt(AdtId::StructId(s), parameters) => { 432 Ty::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => {
433 self.db.struct_data(s).variant_data.field(name).map(|local_id| { 433 self.db.struct_data(s).variant_data.field(name).map(|local_id| {
434 let field = FieldId { parent: s.into(), local_id }; 434 let field = FieldId { parent: s.into(), local_id };
435 self.write_field_resolution(tgt_expr, field); 435 self.write_field_resolution(tgt_expr, field);
436 self.db.field_types(s.into())[field.local_id].clone().subst(&parameters) 436 self.db.field_types(s.into())[field.local_id].clone().subst(&parameters)
437 }) 437 })
438 } 438 }
439 Ty::Adt(AdtId::UnionId(u), parameters) => { 439 Ty::Adt(AdtId(hir_def::AdtId::UnionId(u)), parameters) => {
440 self.db.union_data(u).variant_data.field(name).map(|local_id| { 440 self.db.union_data(u).variant_data.field(name).map(|local_id| {
441 let field = FieldId { parent: u.into(), local_id }; 441 let field = FieldId { parent: u.into(), local_id };
442 self.write_field_resolution(tgt_expr, field); 442 self.write_field_resolution(tgt_expr, field);
@@ -498,7 +498,7 @@ impl<'a> InferenceContext<'a> {
498 _ => (), 498 _ => (),
499 } 499 }
500 sb = sb.fill(repeat_with(|| self.table.new_type_var())); 500 sb = sb.fill(repeat_with(|| self.table.new_type_var()));
501 Ty::Adt(box_, sb.build()) 501 Ty::adt_ty(box_, sb.build())
502 } else { 502 } else {
503 Ty::Unknown 503 Ty::Unknown
504 } 504 }
@@ -586,31 +586,31 @@ impl<'a> InferenceContext<'a> {
586 let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); 586 let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect));
587 match (range_type, lhs_ty, rhs_ty) { 587 match (range_type, lhs_ty, rhs_ty) {
588 (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { 588 (RangeOp::Exclusive, None, None) => match self.resolve_range_full() {
589 Some(adt) => Ty::Adt(adt, Substs::empty()), 589 Some(adt) => Ty::adt_ty(adt, Substs::empty()),
590 None => Ty::Unknown, 590 None => Ty::Unknown,
591 }, 591 },
592 (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { 592 (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() {
593 Some(adt) => Ty::Adt(adt, Substs::single(ty)), 593 Some(adt) => Ty::adt_ty(adt, Substs::single(ty)),
594 None => Ty::Unknown, 594 None => Ty::Unknown,
595 }, 595 },
596 (RangeOp::Inclusive, None, Some(ty)) => { 596 (RangeOp::Inclusive, None, Some(ty)) => {
597 match self.resolve_range_to_inclusive() { 597 match self.resolve_range_to_inclusive() {
598 Some(adt) => Ty::Adt(adt, Substs::single(ty)), 598 Some(adt) => Ty::adt_ty(adt, Substs::single(ty)),
599 None => Ty::Unknown, 599 None => Ty::Unknown,
600 } 600 }
601 } 601 }
602 (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { 602 (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() {
603 Some(adt) => Ty::Adt(adt, Substs::single(ty)), 603 Some(adt) => Ty::adt_ty(adt, Substs::single(ty)),
604 None => Ty::Unknown, 604 None => Ty::Unknown,
605 }, 605 },
606 (RangeOp::Inclusive, Some(_), Some(ty)) => { 606 (RangeOp::Inclusive, Some(_), Some(ty)) => {
607 match self.resolve_range_inclusive() { 607 match self.resolve_range_inclusive() {
608 Some(adt) => Ty::Adt(adt, Substs::single(ty)), 608 Some(adt) => Ty::adt_ty(adt, Substs::single(ty)),
609 None => Ty::Unknown, 609 None => Ty::Unknown,
610 } 610 }
611 } 611 }
612 (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { 612 (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() {
613 Some(adt) => Ty::Adt(adt, Substs::single(ty)), 613 Some(adt) => Ty::adt_ty(adt, Substs::single(ty)),
614 None => Ty::Unknown, 614 None => Ty::Unknown,
615 }, 615 },
616 (RangeOp::Inclusive, _, None) => Ty::Unknown, 616 (RangeOp::Inclusive, _, None) => Ty::Unknown,
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index eb099311c..987793e2e 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -237,7 +237,7 @@ impl<'a> InferenceContext<'a> {
237 }; 237 };
238 238
239 let inner_ty = self.infer_pat(*inner, inner_expected, default_bm); 239 let inner_ty = self.infer_pat(*inner, inner_expected, default_bm);
240 Ty::Adt(box_adt, Substs::single(inner_ty)) 240 Ty::adt_ty(box_adt, Substs::single(inner_ty))
241 } 241 }
242 None => Ty::Unknown, 242 None => Ty::Unknown,
243 }, 243 },
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()),
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 1b5843d48..5fe5b8ad1 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1100,7 +1100,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -
1100fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { 1100fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
1101 let generics = generics(db.upcast(), adt.into()); 1101 let generics = generics(db.upcast(), adt.into());
1102 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1102 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
1103 Binders::new(substs.len(), Ty::Adt(adt, substs)) 1103 Binders::new(substs.len(), Ty::adt_ty(adt, substs))
1104} 1104}
1105 1105
1106fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> { 1106fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index f301a8477..dfcf346fb 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -8,8 +8,8 @@ use arrayvec::ArrayVec;
8use base_db::CrateId; 8use base_db::CrateId;
9use chalk_ir::Mutability; 9use chalk_ir::Mutability;
10use hir_def::{ 10use hir_def::{
11 lang_item::LangItemTarget, AdtId, AssocContainerId, AssocItemId, FunctionId, GenericDefId, 11 lang_item::LangItemTarget, AssocContainerId, AssocItemId, FunctionId, GenericDefId, HasModule,
12 HasModule, ImplId, Lookup, ModuleId, TraitId, TypeAliasId, 12 ImplId, Lookup, ModuleId, TraitId, TypeAliasId,
13}; 13};
14use hir_expand::name::Name; 14use hir_expand::name::Name;
15use rustc_hash::{FxHashMap, FxHashSet}; 15use rustc_hash::{FxHashMap, FxHashSet};
@@ -19,8 +19,8 @@ use crate::{
19 db::HirDatabase, 19 db::HirDatabase,
20 primitive::{self, FloatTy, IntTy, UintTy}, 20 primitive::{self, FloatTy, IntTy, UintTy},
21 utils::all_super_traits, 21 utils::all_super_traits,
22 Canonical, DebruijnIndex, FnPointer, FnSig, InEnvironment, Scalar, Substs, TraitEnvironment, 22 AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, InEnvironment, Scalar, Substs,
23 TraitRef, Ty, TypeWalk, 23 TraitEnvironment, TraitRef, Ty, TypeWalk,
24}; 24};
25 25
26/// This is used as a key for indexing impls. 26/// This is used as a key for indexing impls.
@@ -32,7 +32,7 @@ pub enum TyFingerprint {
32 Never, 32 Never,
33 RawPtr(Mutability), 33 RawPtr(Mutability),
34 Scalar(Scalar), 34 Scalar(Scalar),
35 Adt(AdtId), 35 Adt(hir_def::AdtId),
36 Dyn(TraitId), 36 Dyn(TraitId),
37 Tuple(usize), 37 Tuple(usize),
38 ForeignType(TypeAliasId), 38 ForeignType(TypeAliasId),
@@ -50,7 +50,7 @@ impl TyFingerprint {
50 &Ty::Slice(..) => TyFingerprint::Slice, 50 &Ty::Slice(..) => TyFingerprint::Slice,
51 &Ty::Array(..) => TyFingerprint::Array, 51 &Ty::Array(..) => TyFingerprint::Array,
52 &Ty::Scalar(scalar) => TyFingerprint::Scalar(scalar), 52 &Ty::Scalar(scalar) => TyFingerprint::Scalar(scalar),
53 &Ty::Adt(adt, _) => TyFingerprint::Adt(adt), 53 &Ty::Adt(AdtId(adt), _) => TyFingerprint::Adt(adt),
54 &Ty::Tuple(cardinality, _) => TyFingerprint::Tuple(cardinality), 54 &Ty::Tuple(cardinality, _) => TyFingerprint::Tuple(cardinality),
55 &Ty::Raw(mutability, ..) => TyFingerprint::RawPtr(mutability), 55 &Ty::Raw(mutability, ..) => TyFingerprint::RawPtr(mutability),
56 &Ty::ForeignType(alias_id, ..) => TyFingerprint::ForeignType(alias_id), 56 &Ty::ForeignType(alias_id, ..) => TyFingerprint::ForeignType(alias_id),
@@ -231,7 +231,7 @@ impl Ty {
231 let mod_to_crate_ids = |module: ModuleId| Some(std::iter::once(module.krate()).collect()); 231 let mod_to_crate_ids = |module: ModuleId| Some(std::iter::once(module.krate()).collect());
232 232
233 let lang_item_targets = match self { 233 let lang_item_targets = match self {
234 Ty::Adt(def_id, _) => { 234 Ty::Adt(AdtId(def_id), _) => {
235 return mod_to_crate_ids(def_id.module(db.upcast())); 235 return mod_to_crate_ids(def_id.module(db.upcast()));
236 } 236 }
237 Ty::ForeignType(type_alias_id) => { 237 Ty::ForeignType(type_alias_id) => {
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index e513fa8f4..4378a9723 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -315,9 +315,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
315 let id = from_chalk(self.db, trait_id); 315 let id = from_chalk(self.db, trait_id);
316 self.db.trait_data(id).name.to_string() 316 self.db.trait_data(id).name.to_string()
317 } 317 }
318 fn adt_name(&self, adt_id: chalk_ir::AdtId<Interner>) -> String { 318 fn adt_name(&self, chalk_ir::AdtId(adt_id): AdtId) -> String {
319 let id = from_chalk(self.db, adt_id); 319 match adt_id {
320 match id {
321 hir_def::AdtId::StructId(id) => self.db.struct_data(id).name.to_string(), 320 hir_def::AdtId::StructId(id) => self.db.struct_data(id).name.to_string(),
322 hir_def::AdtId::EnumId(id) => self.db.enum_data(id).name.to_string(), 321 hir_def::AdtId::EnumId(id) => self.db.enum_data(id).name.to_string(),
323 hir_def::AdtId::UnionId(id) => self.db.union_data(id).name.to_string(), 322 hir_def::AdtId::UnionId(id) => self.db.union_data(id).name.to_string(),
@@ -488,8 +487,8 @@ pub(crate) fn struct_datum_query(
488 struct_id: AdtId, 487 struct_id: AdtId,
489) -> Arc<StructDatum> { 488) -> Arc<StructDatum> {
490 debug!("struct_datum {:?}", struct_id); 489 debug!("struct_datum {:?}", struct_id);
491 let adt_id = from_chalk(db, struct_id); 490 let type_ctor = Ty::Adt(struct_id, Substs::empty());
492 let type_ctor = Ty::Adt(adt_id, Substs::empty()); 491 let chalk_ir::AdtId(adt_id) = struct_id;
493 debug!("struct {:?} = {:?}", struct_id, type_ctor); 492 debug!("struct {:?} = {:?}", struct_id, type_ctor);
494 let num_params = generics(db.upcast(), adt_id.into()).len(); 493 let num_params = generics(db.upcast(), adt_id.into()).len();
495 let upstream = adt_id.module(db.upcast()).krate() != krate; 494 let upstream = adt_id.module(db.upcast()).krate() != krate;
@@ -684,10 +683,9 @@ pub(crate) fn fn_def_variance_query(
684pub(crate) fn adt_variance_query( 683pub(crate) fn adt_variance_query(
685 db: &dyn HirDatabase, 684 db: &dyn HirDatabase,
686 _krate: CrateId, 685 _krate: CrateId,
687 adt_id: AdtId, 686 chalk_ir::AdtId(adt_id): AdtId,
688) -> Variances { 687) -> Variances {
689 let adt: crate::AdtId = from_chalk(db, adt_id); 688 let generic_params = generics(db.upcast(), adt_id.into());
690 let generic_params = generics(db.upcast(), adt.into());
691 Variances::from_iter( 689 Variances::from_iter(
692 &Interner, 690 &Interner,
693 std::iter::repeat(chalk_ir::Variance::Invariant).take(generic_params.len()), 691 std::iter::repeat(chalk_ir::Variance::Invariant).take(generic_params.len()),
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index db1760e6c..3a08b67e9 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -86,7 +86,7 @@ impl ToChalk for Ty {
86 86
87 Ty::Adt(adt_id, substs) => { 87 Ty::Adt(adt_id, substs) => {
88 let substitution = substs.to_chalk(db); 88 let substitution = substs.to_chalk(db);
89 chalk_ir::TyKind::Adt(chalk_ir::AdtId(adt_id), substitution).intern(&Interner) 89 chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner)
90 } 90 }
91 Ty::Alias(AliasTy::Projection(proj_ty)) => { 91 Ty::Alias(AliasTy::Projection(proj_ty)) => {
92 let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); 92 let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db);
@@ -183,7 +183,7 @@ impl ToChalk for Ty {
183 Ty::Dyn(predicates) 183 Ty::Dyn(predicates)
184 } 184 }
185 185
186 chalk_ir::TyKind::Adt(struct_id, subst) => Ty::Adt(struct_id.0, from_chalk(db, subst)), 186 chalk_ir::TyKind::Adt(adt_id, subst) => Ty::Adt(adt_id, from_chalk(db, subst)),
187 chalk_ir::TyKind::AssociatedType(type_id, subst) => Ty::AssociatedType( 187 chalk_ir::TyKind::AssociatedType(type_id, subst) => Ty::AssociatedType(
188 from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0, 188 from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0,
189 from_chalk(db, subst), 189 from_chalk(db, subst),
@@ -325,18 +325,6 @@ impl ToChalk for hir_def::ImplId {
325 } 325 }
326} 326}
327 327
328impl ToChalk for hir_def::AdtId {
329 type Chalk = AdtId;
330
331 fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk {
332 chalk_ir::AdtId(self.into())
333 }
334
335 fn from_chalk(_db: &dyn HirDatabase, id: AdtId) -> Self {
336 id.0
337 }
338}
339
340impl ToChalk for CallableDefId { 328impl ToChalk for CallableDefId {
341 type Chalk = FnDefId; 329 type Chalk = FnDefId;
342 330