aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r--crates/ra_hir_ty/src/db.rs4
-rw-r--r--crates/ra_hir_ty/src/expr.rs14
-rw-r--r--crates/ra_hir_ty/src/infer.rs16
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs8
-rw-r--r--crates/ra_hir_ty/src/infer/pat.rs4
-rw-r--r--crates/ra_hir_ty/src/lower.rs6
6 files changed, 25 insertions, 27 deletions
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs
index 9e5dfeab3..fdb49560b 100644
--- a/crates/ra_hir_ty/src/db.rs
+++ b/crates/ra_hir_ty/src/db.rs
@@ -3,7 +3,7 @@
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{ 5use hir_def::{
6 db::DefDatabase, DefWithBodyId, GenericDefId, ImplId, LocalStructFieldId, TraitId, TypeParamId, 6 db::DefDatabase, DefWithBodyId, GenericDefId, ImplId, LocalFieldId, TraitId, TypeParamId,
7 VariantId, 7 VariantId,
8}; 8};
9use ra_arena::map::ArenaMap; 9use ra_arena::map::ArenaMap;
@@ -43,7 +43,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
43 fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>; 43 fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>;
44 44
45 #[salsa::invoke(crate::lower::field_types_query)] 45 #[salsa::invoke(crate::lower::field_types_query)]
46 fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Binders<Ty>>>; 46 fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>>;
47 47
48 #[salsa::invoke(crate::callable_item_sig)] 48 #[salsa::invoke(crate::callable_item_sig)]
49 fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig; 49 fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig;
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index fd59f4320..f04968e14 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -24,7 +24,7 @@ pub use hir_def::{
24 ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, 24 ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp,
25 MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, UnaryOp, 25 MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, UnaryOp,
26 }, 26 },
27 LocalStructFieldId, VariantId, 27 LocalFieldId, VariantId,
28}; 28};
29 29
30pub struct ExprValidator<'a, 'b: 'a> { 30pub struct ExprValidator<'a, 'b: 'a> {
@@ -83,7 +83,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
83 id: ExprId, 83 id: ExprId,
84 db: &dyn HirDatabase, 84 db: &dyn HirDatabase,
85 variant_def: VariantId, 85 variant_def: VariantId,
86 missed_fields: Vec<LocalStructFieldId>, 86 missed_fields: Vec<LocalFieldId>,
87 ) { 87 ) {
88 // XXX: only look at source_map if we do have missing fields 88 // XXX: only look at source_map if we do have missing fields
89 let (_, source_map) = db.body_with_source_map(self.func.into()); 89 let (_, source_map) = db.body_with_source_map(self.func.into());
@@ -112,7 +112,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
112 id: PatId, 112 id: PatId,
113 db: &dyn HirDatabase, 113 db: &dyn HirDatabase,
114 variant_def: VariantId, 114 variant_def: VariantId,
115 missed_fields: Vec<LocalStructFieldId>, 115 missed_fields: Vec<LocalFieldId>,
116 ) { 116 ) {
117 // XXX: only look at source_map if we do have missing fields 117 // XXX: only look at source_map if we do have missing fields
118 let (_, source_map) = db.body_with_source_map(self.func.into()); 118 let (_, source_map) = db.body_with_source_map(self.func.into());
@@ -256,7 +256,7 @@ pub fn record_literal_missing_fields(
256 infer: &InferenceResult, 256 infer: &InferenceResult,
257 id: ExprId, 257 id: ExprId,
258 expr: &Expr, 258 expr: &Expr,
259) -> Option<(VariantId, Vec<LocalStructFieldId>, /*exhaustive*/ bool)> { 259) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
260 let (fields, exhausitve) = match expr { 260 let (fields, exhausitve) = match expr {
261 Expr::RecordLit { path: _, fields, spread } => (fields, spread.is_none()), 261 Expr::RecordLit { path: _, fields, spread } => (fields, spread.is_none()),
262 _ => return None, 262 _ => return None,
@@ -270,7 +270,7 @@ pub fn record_literal_missing_fields(
270 let variant_data = variant_data(db.upcast(), variant_def); 270 let variant_data = variant_data(db.upcast(), variant_def);
271 271
272 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); 272 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect();
273 let missed_fields: Vec<LocalStructFieldId> = variant_data 273 let missed_fields: Vec<LocalFieldId> = variant_data
274 .fields() 274 .fields()
275 .iter() 275 .iter()
276 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) }) 276 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) })
@@ -286,7 +286,7 @@ pub fn record_pattern_missing_fields(
286 infer: &InferenceResult, 286 infer: &InferenceResult,
287 id: PatId, 287 id: PatId,
288 pat: &Pat, 288 pat: &Pat,
289) -> Option<(VariantId, Vec<LocalStructFieldId>, /*exhaustive*/ bool)> { 289) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
290 let (fields, exhaustive) = match pat { 290 let (fields, exhaustive) = match pat {
291 Pat::Record { path: _, args, ellipsis } => (args, !ellipsis), 291 Pat::Record { path: _, args, ellipsis } => (args, !ellipsis),
292 _ => return None, 292 _ => return None,
@@ -300,7 +300,7 @@ pub fn record_pattern_missing_fields(
300 let variant_data = variant_data(db.upcast(), variant_def); 300 let variant_data = variant_data(db.upcast(), variant_def);
301 301
302 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); 302 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect();
303 let missed_fields: Vec<LocalStructFieldId> = variant_data 303 let missed_fields: Vec<LocalFieldId> = variant_data
304 .fields() 304 .fields()
305 .iter() 305 .iter()
306 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) }) 306 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) })
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index dfb6a435f..6a53be621 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -28,7 +28,7 @@ use hir_def::{
28 path::{path, Path}, 28 path::{path, Path},
29 resolver::{HasResolver, Resolver, TypeNs}, 29 resolver::{HasResolver, Resolver, TypeNs},
30 type_ref::{Mutability, TypeRef}, 30 type_ref::{Mutability, TypeRef},
31 AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TraitId, TypeAliasId, VariantId, 31 AdtId, AssocItemId, DefWithBodyId, FieldId, FunctionId, TraitId, TypeAliasId, VariantId,
32}; 32};
33use hir_expand::{diagnostics::DiagnosticSink, name::name}; 33use hir_expand::{diagnostics::DiagnosticSink, name::name};
34use ra_arena::map::ArenaMap; 34use ra_arena::map::ArenaMap;
@@ -124,10 +124,10 @@ pub struct InferenceResult {
124 /// For each method call expr, records the function it resolves to. 124 /// For each method call expr, records the function it resolves to.
125 method_resolutions: FxHashMap<ExprId, FunctionId>, 125 method_resolutions: FxHashMap<ExprId, FunctionId>,
126 /// For each field access expr, records the field it resolves to. 126 /// For each field access expr, records the field it resolves to.
127 field_resolutions: FxHashMap<ExprId, StructFieldId>, 127 field_resolutions: FxHashMap<ExprId, FieldId>,
128 /// For each field in record literal, records the field it resolves to. 128 /// For each field in record literal, records the field it resolves to.
129 record_field_resolutions: FxHashMap<ExprId, StructFieldId>, 129 record_field_resolutions: FxHashMap<ExprId, FieldId>,
130 record_field_pat_resolutions: FxHashMap<PatId, StructFieldId>, 130 record_field_pat_resolutions: FxHashMap<PatId, FieldId>,
131 /// For each struct literal, records the variant it resolves to. 131 /// For each struct literal, records the variant it resolves to.
132 variant_resolutions: FxHashMap<ExprOrPatId, VariantId>, 132 variant_resolutions: FxHashMap<ExprOrPatId, VariantId>,
133 /// For each associated item record what it resolves to 133 /// For each associated item record what it resolves to
@@ -142,13 +142,13 @@ impl InferenceResult {
142 pub fn method_resolution(&self, expr: ExprId) -> Option<FunctionId> { 142 pub fn method_resolution(&self, expr: ExprId) -> Option<FunctionId> {
143 self.method_resolutions.get(&expr).copied() 143 self.method_resolutions.get(&expr).copied()
144 } 144 }
145 pub fn field_resolution(&self, expr: ExprId) -> Option<StructFieldId> { 145 pub fn field_resolution(&self, expr: ExprId) -> Option<FieldId> {
146 self.field_resolutions.get(&expr).copied() 146 self.field_resolutions.get(&expr).copied()
147 } 147 }
148 pub fn record_field_resolution(&self, expr: ExprId) -> Option<StructFieldId> { 148 pub fn record_field_resolution(&self, expr: ExprId) -> Option<FieldId> {
149 self.record_field_resolutions.get(&expr).copied() 149 self.record_field_resolutions.get(&expr).copied()
150 } 150 }
151 pub fn record_field_pat_resolution(&self, pat: PatId) -> Option<StructFieldId> { 151 pub fn record_field_pat_resolution(&self, pat: PatId) -> Option<FieldId> {
152 self.record_field_pat_resolutions.get(&pat).copied() 152 self.record_field_pat_resolutions.get(&pat).copied()
153 } 153 }
154 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId> { 154 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId> {
@@ -249,7 +249,7 @@ impl<'a> InferenceContext<'a> {
249 self.result.method_resolutions.insert(expr, func); 249 self.result.method_resolutions.insert(expr, func);
250 } 250 }
251 251
252 fn write_field_resolution(&mut self, expr: ExprId, field: StructFieldId) { 252 fn write_field_resolution(&mut self, expr: ExprId, field: FieldId) {
253 self.result.field_resolutions.insert(expr, field); 253 self.result.field_resolutions.insert(expr, field);
254 } 254 }
255 255
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 1fdb235a0..83f946eee 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_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, Lookup, StructFieldId, 11 AdtId, AssocContainerId, FieldId, Lookup,
12}; 12};
13use hir_expand::name::Name; 13use hir_expand::name::Name;
14use ra_syntax::ast::RangeOp; 14use ra_syntax::ast::RangeOp;
@@ -216,9 +216,7 @@ impl<'a> InferenceContext<'a> {
216 for (field_idx, field) in fields.iter().enumerate() { 216 for (field_idx, field) in fields.iter().enumerate() {
217 let field_def = 217 let field_def =
218 variant_data.as_ref().and_then(|it| match it.field(&field.name) { 218 variant_data.as_ref().and_then(|it| match it.field(&field.name) {
219 Some(local_id) => { 219 Some(local_id) => Some(FieldId { parent: def_id.unwrap(), local_id }),
220 Some(StructFieldId { parent: def_id.unwrap(), local_id })
221 }
222 None => { 220 None => {
223 self.push_diagnostic(InferenceDiagnostic::NoSuchField { 221 self.push_diagnostic(InferenceDiagnostic::NoSuchField {
224 expr: tgt_expr, 222 expr: tgt_expr,
@@ -257,7 +255,7 @@ impl<'a> InferenceContext<'a> {
257 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), 255 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()),
258 TypeCtor::Adt(AdtId::StructId(s)) => { 256 TypeCtor::Adt(AdtId::StructId(s)) => {
259 self.db.struct_data(s).variant_data.field(name).map(|local_id| { 257 self.db.struct_data(s).variant_data.field(name).map(|local_id| {
260 let field = StructFieldId { parent: s.into(), local_id }; 258 let field = FieldId { parent: s.into(), local_id };
261 self.write_field_resolution(tgt_expr, field); 259 self.write_field_resolution(tgt_expr, field);
262 self.db.field_types(s.into())[field.local_id] 260 self.db.field_types(s.into())[field.local_id]
263 .clone() 261 .clone()
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs
index 7c2ad4384..54ec870df 100644
--- a/crates/ra_hir_ty/src/infer/pat.rs
+++ b/crates/ra_hir_ty/src/infer/pat.rs
@@ -7,7 +7,7 @@ use hir_def::{
7 expr::{BindingAnnotation, Pat, PatId, RecordFieldPat}, 7 expr::{BindingAnnotation, Pat, PatId, RecordFieldPat},
8 path::Path, 8 path::Path,
9 type_ref::Mutability, 9 type_ref::Mutability,
10 StructFieldId, 10 FieldId,
11}; 11};
12use hir_expand::name::Name; 12use hir_expand::name::Name;
13use test_utils::tested_by; 13use test_utils::tested_by;
@@ -69,7 +69,7 @@ impl<'a> InferenceContext<'a> {
69 for subpat in subpats { 69 for subpat in subpats {
70 let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); 70 let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name));
71 if let Some(local_id) = matching_field { 71 if let Some(local_id) = matching_field {
72 let field_def = StructFieldId { parent: def.unwrap(), local_id }; 72 let field_def = FieldId { parent: def.unwrap(), local_id };
73 self.result.record_field_pat_resolutions.insert(subpat.pat, field_def); 73 self.result.record_field_pat_resolutions.insert(subpat.pat, field_def);
74 } 74 }
75 75
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index c2812e178..b57214296 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -18,8 +18,8 @@ use hir_def::{
18 resolver::{HasResolver, Resolver, TypeNs}, 18 resolver::{HasResolver, Resolver, TypeNs},
19 type_ref::{TypeBound, TypeRef}, 19 type_ref::{TypeBound, TypeRef},
20 AdtId, AssocContainerId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, HasModule, 20 AdtId, AssocContainerId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, HasModule,
21 ImplId, LocalStructFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, 21 ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId,
22 UnionId, VariantId, 22 VariantId,
23}; 23};
24use ra_arena::map::ArenaMap; 24use ra_arena::map::ArenaMap;
25use ra_db::CrateId; 25use ra_db::CrateId;
@@ -682,7 +682,7 @@ pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig {
682pub(crate) fn field_types_query( 682pub(crate) fn field_types_query(
683 db: &dyn HirDatabase, 683 db: &dyn HirDatabase,
684 variant_id: VariantId, 684 variant_id: VariantId,
685) -> Arc<ArenaMap<LocalStructFieldId, Binders<Ty>>> { 685) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>> {
686 let var_data = variant_data(db.upcast(), variant_id); 686 let var_data = variant_data(db.upcast(), variant_id);
687 let (resolver, def): (_, GenericDefId) = match variant_id { 687 let (resolver, def): (_, GenericDefId) = match variant_id {
688 VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()), 688 VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()),