aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-26 11:29:12 +0000
committerAleksey Kladov <[email protected]>2019-11-26 11:29:12 +0000
commita443b5033c2e95ee58bf086f7093ddc610d4f78f (patch)
tree5f05620adde03f7cb521b2f59aad6b2470e6272e /crates/ra_hir/src/ty
parente5eadb339039e21718d382c0b3d02a4bf053b3f4 (diff)
Id-ify Ty::Adt
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer.rs4
-rw-r--r--crates/ra_hir/src/ty/infer/coerce.rs12
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs21
-rw-r--r--crates/ra_hir/src/ty/lower.rs2
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs6
5 files changed, 25 insertions, 20 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 6fd00d457..fce45321d 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -598,10 +598,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
598 trait_.associated_type_by_name(self.db, &name::OUTPUT_TYPE) 598 trait_.associated_type_by_name(self.db, &name::OUTPUT_TYPE)
599 } 599 }
600 600
601 fn resolve_boxed_box(&self) -> Option<Adt> { 601 fn resolve_boxed_box(&self) -> Option<AdtId> {
602 let path = known::std_boxed_box(); 602 let path = known::std_boxed_box();
603 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; 603 let struct_ = self.resolver.resolve_known_struct(self.db, &path)?;
604 Some(Adt::Struct(struct_.into())) 604 Some(struct_.into())
605 } 605 }
606} 606}
607 607
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs
index bb9a2e427..5ed4470af 100644
--- a/crates/ra_hir/src/ty/infer/coerce.rs
+++ b/crates/ra_hir/src/ty/infer/coerce.rs
@@ -4,14 +4,14 @@
4//! 4//!
5//! See: https://doc.rust-lang.org/nomicon/coercions.html 5//! See: https://doc.rust-lang.org/nomicon/coercions.html
6 6
7use hir_def::{lang_item::LangItemTarget, resolver::Resolver}; 7use hir_def::{lang_item::LangItemTarget, resolver::Resolver, AdtId};
8use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
9use test_utils::tested_by; 9use test_utils::tested_by;
10 10
11use crate::{ 11use crate::{
12 db::HirDatabase, 12 db::HirDatabase,
13 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, 13 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk},
14 Adt, Mutability, 14 Mutability,
15}; 15};
16 16
17use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue}; 17use super::{InEnvironment, InferTy, InferenceContext, TypeVarValue};
@@ -242,11 +242,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
242 // - T is not part of the type of any other fields 242 // - T is not part of the type of any other fields
243 // - Bar<T>: Unsize<Bar<U>>, if the last field of Foo has type Bar<T> 243 // - Bar<T>: Unsize<Bar<U>>, if the last field of Foo has type Bar<T>
244 ( 244 (
245 ty_app!(TypeCtor::Adt(Adt::Struct(struct1)), st1), 245 ty_app!(TypeCtor::Adt(AdtId::StructId(struct1)), st1),
246 ty_app!(TypeCtor::Adt(Adt::Struct(struct2)), st2), 246 ty_app!(TypeCtor::Adt(AdtId::StructId(struct2)), st2),
247 ) if struct1 == struct2 => { 247 ) if struct1 == struct2 => {
248 let field_tys = self.db.field_types(struct1.id.into()); 248 let field_tys = self.db.field_types((*struct1).into());
249 let struct_data = self.db.struct_data(struct1.id); 249 let struct_data = self.db.struct_data(*struct1);
250 250
251 let mut fields = struct_data.variant_data.fields().iter(); 251 let mut fields = struct_data.variant_data.fields().iter();
252 let (last_field_id, _data) = fields.next_back()?; 252 let (last_field_id, _data) = fields.next_back()?;
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index 316cdc880..3d0895dc6 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -8,7 +8,7 @@ use hir_def::{
8 generics::GenericParams, 8 generics::GenericParams,
9 path::{GenericArg, GenericArgs}, 9 path::{GenericArg, GenericArgs},
10 resolver::resolver_for_expr, 10 resolver::resolver_for_expr,
11 ContainerId, Lookup, 11 AdtId, ContainerId, Lookup, StructFieldId,
12}; 12};
13use hir_expand::name; 13use hir_expand::name;
14 14
@@ -20,7 +20,7 @@ use crate::{
20 Mutability, Namespace, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, 20 Mutability, Namespace, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty,
21 TypeCtor, TypeWalk, Uncertain, 21 TypeCtor, TypeWalk, Uncertain,
22 }, 22 },
23 Adt, Name, 23 Name,
24}; 24};
25 25
26use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; 26use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch};
@@ -259,14 +259,17 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
259 TypeCtor::Tuple { .. } => name 259 TypeCtor::Tuple { .. } => name
260 .as_tuple_index() 260 .as_tuple_index()
261 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), 261 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()),
262 TypeCtor::Adt(Adt::Struct(s)) => s.field(self.db, name).map(|field| { 262 TypeCtor::Adt(AdtId::StructId(s)) => {
263 self.write_field_resolution(tgt_expr, field); 263 self.db.struct_data(s).variant_data.field(name).map(|local_id| {
264 self.db.field_types(s.id.into())[field.id] 264 let field = StructFieldId { parent: s.into(), local_id }.into();
265 .clone() 265 self.write_field_resolution(tgt_expr, field);
266 .subst(&a_ty.parameters) 266 self.db.field_types(s.into())[field.id]
267 }), 267 .clone()
268 .subst(&a_ty.parameters)
269 })
270 }
268 // FIXME: 271 // FIXME:
269 TypeCtor::Adt(Adt::Union(_)) => None, 272 TypeCtor::Adt(AdtId::UnionId(_)) => None,
270 _ => None, 273 _ => None,
271 }, 274 },
272 _ => None, 275 _ => None,
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index d7d4bb0d6..485871e69 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -762,7 +762,7 @@ fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt>) -> Ty {
762 let adt = adt.into(); 762 let adt = adt.into();
763 let adt_id: AdtId = adt.into(); 763 let adt_id: AdtId = adt.into();
764 let generics = db.generic_params(adt_id.into()); 764 let generics = db.generic_params(adt_id.into());
765 Ty::apply(TypeCtor::Adt(adt), Substs::identity(&generics)) 765 Ty::apply(TypeCtor::Adt(adt_id), Substs::identity(&generics))
766} 766}
767 767
768fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { 768fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index c5ab690eb..7f0ff2e8c 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -5,7 +5,7 @@
5use std::sync::Arc; 5use std::sync::Arc;
6 6
7use arrayvec::ArrayVec; 7use arrayvec::ArrayVec;
8use hir_def::{lang_item::LangItemTarget, resolver::Resolver, AstItemDef}; 8use hir_def::{lang_item::LangItemTarget, resolver::Resolver, AstItemDef, HasModule};
9use rustc_hash::FxHashMap; 9use rustc_hash::FxHashMap;
10 10
11use crate::{ 11use crate::{
@@ -102,7 +102,9 @@ fn def_crates(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<ArrayV
102 102
103 let lang_item_targets = match ty { 103 let lang_item_targets = match ty {
104 Ty::Apply(a_ty) => match a_ty.ctor { 104 Ty::Apply(a_ty) => match a_ty.ctor {
105 TypeCtor::Adt(def_id) => return Some(std::iter::once(def_id.krate(db)?).collect()), 105 TypeCtor::Adt(def_id) => {
106 return Some(std::iter::once(def_id.module(db).krate.into()).collect())
107 }
106 TypeCtor::Bool => lang_item_crate!("bool"), 108 TypeCtor::Bool => lang_item_crate!("bool"),
107 TypeCtor::Char => lang_item_crate!("char"), 109 TypeCtor::Char => lang_item_crate!("char"),
108 TypeCtor::Float(Uncertain::Known(f)) => match f.bitness { 110 TypeCtor::Float(Uncertain::Known(f)) => match f.bitness {