Skip to content

Commit 2798bee

Browse files
bors[bot]matklad
andauthored
Merge #2428
2428: Remove TypableDef r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 35f57f3 + 12501fc commit 2798bee

File tree

12 files changed

+131
-219
lines changed

12 files changed

+131
-219
lines changed

crates/ra_hir/src/code_model.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,6 @@ impl VariantDef {
534534
}
535535
}
536536

537-
pub(crate) fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> {
538-
match self {
539-
VariantDef::Struct(it) => it.field(db, name),
540-
VariantDef::Union(it) => it.field(db, name),
541-
VariantDef::EnumVariant(it) => it.field(db, name),
542-
}
543-
}
544-
545537
pub fn module(self, db: &impl HirDatabase) -> Module {
546538
match self {
547539
VariantDef::Struct(it) => it.module(db),
@@ -618,7 +610,7 @@ impl Function {
618610
}
619611

620612
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
621-
db.infer(self.into())
613+
db.infer(self.id.into())
622614
}
623615

624616
/// The containing impl block, if this is a method.
@@ -647,7 +639,7 @@ impl Function {
647639

648640
pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
649641
let infer = self.infer(db);
650-
infer.add_diagnostics(db, self, sink);
642+
infer.add_diagnostics(db, self.id, sink);
651643
let mut validator = ExprValidator::new(self, infer, sink);
652644
validator.validate_body(db);
653645
}
@@ -672,7 +664,7 @@ impl Const {
672664
}
673665

674666
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
675-
db.infer(self.into())
667+
db.infer(self.id.into())
676668
}
677669

678670
/// The containing impl block, if this is a type alias.
@@ -715,7 +707,7 @@ impl Static {
715707
}
716708

717709
pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
718-
db.infer(self.into())
710+
db.infer(self.id.into())
719711
}
720712
}
721713

@@ -908,9 +900,9 @@ impl Local {
908900
}
909901

910902
pub fn ty(self, db: &impl HirDatabase) -> Type {
911-
let infer = db.infer(self.parent);
912-
let ty = infer[self.pat_id].clone();
913903
let def = DefWithBodyId::from(self.parent);
904+
let infer = db.infer(def);
905+
let ty = infer[self.pat_id].clone();
914906
let resolver = def.resolver(db);
915907
let krate = def.module(db).krate;
916908
let environment = TraitEnvironment::lower(db, &resolver);

crates/ra_hir/src/db.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
33
use std::sync::Arc;
44

5-
use hir_def::{GenericDefId, ImplId, LocalStructFieldId, TraitId, VariantId};
5+
use hir_def::{DefWithBodyId, GenericDefId, ImplId, LocalStructFieldId, TraitId, VariantId};
66
use ra_arena::map::ArenaMap;
77
use ra_db::{salsa, CrateId};
88

9-
use crate::{
10-
ty::{
11-
method_resolution::CrateImplBlocks,
12-
traits::{AssocTyValue, Impl},
13-
CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TyDefId, TypeCtor,
14-
ValueTyDefId,
15-
},
16-
DefWithBody,
9+
use crate::ty::{
10+
method_resolution::CrateImplBlocks,
11+
traits::{AssocTyValue, Impl},
12+
CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TyDefId, TypeCtor,
13+
ValueTyDefId,
1714
};
1815

1916
pub use hir_def::db::{
@@ -32,7 +29,7 @@ pub use hir_expand::db::{
3229
#[salsa::requires(salsa::Database)]
3330
pub trait HirDatabase: DefDatabase {
3431
#[salsa::invoke(crate::ty::infer_query)]
35-
fn infer(&self, def: DefWithBody) -> Arc<InferenceResult>;
32+
fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
3633

3734
#[salsa::invoke(crate::ty::ty_query)]
3835
fn ty(&self, def: TyDefId) -> Ty;

crates/ra_hir/src/from_id.rs

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
//! are splitting the hir.
55
66
use hir_def::{
7-
AdtId, AssocItemId, AttrDefId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
8-
GenericDefId, ModuleDefId, StaticId, StructFieldId, StructId, TypeAliasId, UnionId, VariantId,
7+
AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, GenericDefId, ModuleDefId,
8+
StructFieldId, VariantId,
99
};
1010

1111
use crate::{
12-
ty::TypableDef, Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function,
13-
GenericDef, ModuleDef, Static, StructField, TypeAlias, VariantDef,
12+
Adt, AssocItem, AttrDef, Crate, DefWithBody, EnumVariant, GenericDef, ModuleDef, StructField,
13+
VariantDef,
1414
};
1515

1616
impl From<ra_db::CrateId> for Crate {
@@ -137,58 +137,6 @@ impl From<GenericDef> for GenericDefId {
137137
}
138138
}
139139

140-
impl From<AdtId> for TypableDef {
141-
fn from(id: AdtId) -> Self {
142-
Adt::from(id).into()
143-
}
144-
}
145-
146-
impl From<StructId> for TypableDef {
147-
fn from(id: StructId) -> Self {
148-
AdtId::StructId(id).into()
149-
}
150-
}
151-
152-
impl From<UnionId> for TypableDef {
153-
fn from(id: UnionId) -> Self {
154-
AdtId::UnionId(id).into()
155-
}
156-
}
157-
158-
impl From<EnumId> for TypableDef {
159-
fn from(id: EnumId) -> Self {
160-
AdtId::EnumId(id).into()
161-
}
162-
}
163-
164-
impl From<EnumVariantId> for TypableDef {
165-
fn from(id: EnumVariantId) -> Self {
166-
EnumVariant::from(id).into()
167-
}
168-
}
169-
170-
impl From<TypeAliasId> for TypableDef {
171-
fn from(id: TypeAliasId) -> Self {
172-
TypeAlias::from(id).into()
173-
}
174-
}
175-
176-
impl From<FunctionId> for TypableDef {
177-
fn from(id: FunctionId) -> Self {
178-
Function::from(id).into()
179-
}
180-
}
181-
impl From<ConstId> for TypableDef {
182-
fn from(id: ConstId) -> Self {
183-
Const::from(id).into()
184-
}
185-
}
186-
impl From<StaticId> for TypableDef {
187-
fn from(id: StaticId) -> Self {
188-
Static::from(id).into()
189-
}
190-
}
191-
192140
impl From<Adt> for GenericDefId {
193141
fn from(id: Adt) -> Self {
194142
match id {

crates/ra_hir/src/source_binder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl SourceAnalyzer {
168168
resolver,
169169
body_owner: Some(def),
170170
body_source_map: Some(source_map),
171-
infer: Some(db.infer(def)),
171+
infer: Some(db.infer(def.into())),
172172
scopes: Some(scopes),
173173
file_id: node.file_id,
174174
}
@@ -214,27 +214,27 @@ impl SourceAnalyzer {
214214

215215
pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
216216
let expr_id = self.expr_id(&call.clone().into())?;
217-
self.infer.as_ref()?.method_resolution(expr_id)
217+
self.infer.as_ref()?.method_resolution(expr_id).map(Function::from)
218218
}
219219

220220
pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<crate::StructField> {
221221
let expr_id = self.expr_id(&field.clone().into())?;
222-
self.infer.as_ref()?.field_resolution(expr_id)
222+
self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into())
223223
}
224224

225225
pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<crate::StructField> {
226226
let expr_id = self.expr_id(&field.expr()?)?;
227-
self.infer.as_ref()?.record_field_resolution(expr_id)
227+
self.infer.as_ref()?.record_field_resolution(expr_id).map(|it| it.into())
228228
}
229229

230230
pub fn resolve_record_literal(&self, record_lit: &ast::RecordLit) -> Option<crate::VariantDef> {
231231
let expr_id = self.expr_id(&record_lit.clone().into())?;
232-
self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
232+
self.infer.as_ref()?.variant_resolution_for_expr(expr_id).map(|it| it.into())
233233
}
234234

235235
pub fn resolve_record_pattern(&self, record_pat: &ast::RecordPat) -> Option<crate::VariantDef> {
236236
let pat_id = self.pat_id(&record_pat.clone().into())?;
237-
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
237+
self.infer.as_ref()?.variant_resolution_for_pat(pat_id).map(|it| it.into())
238238
}
239239

240240
pub fn resolve_macro_call(
@@ -297,13 +297,13 @@ impl SourceAnalyzer {
297297
if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
298298
let expr_id = self.expr_id(&path_expr.into())?;
299299
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) {
300-
return Some(PathResolution::AssocItem(assoc));
300+
return Some(PathResolution::AssocItem(assoc.into()));
301301
}
302302
}
303303
if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
304304
let pat_id = self.pat_id(&path_pat.into())?;
305305
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
306-
return Some(PathResolution::AssocItem(assoc));
306+
return Some(PathResolution::AssocItem(assoc.into()));
307307
}
308308
}
309309
// This must be a normal source file rather than macro file.

crates/ra_hir/src/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use lower::CallableDef;
3838
pub(crate) use lower::{
3939
callable_item_sig, field_types_query, generic_defaults_query,
4040
generic_predicates_for_param_query, generic_predicates_query, ty_query, value_ty_query,
41-
TyDefId, TypableDef, ValueTyDefId,
41+
TyDefId, ValueTyDefId,
4242
};
4343
pub(crate) use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
4444

0 commit comments

Comments
 (0)