@@ -22,28 +22,28 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
22
22
use rustc_hash:: FxHashMap ;
23
23
24
24
use hir_def:: {
25
+ body:: Body ,
25
26
data:: { ConstData , FunctionData } ,
26
- path:: known,
27
+ expr:: { BindingAnnotation , ExprId , PatId } ,
28
+ path:: { known, Path } ,
27
29
resolver:: { HasResolver , Resolver , TypeNs } ,
28
30
type_ref:: { Mutability , TypeRef } ,
29
- AdtId , AssocItemId , DefWithBodyId ,
31
+ AdtId , AssocItemId , DefWithBodyId , FunctionId , StructFieldId , TypeAliasId ,
30
32
} ;
31
33
use hir_expand:: { diagnostics:: DiagnosticSink , name} ;
32
34
use ra_arena:: map:: ArenaMap ;
33
35
use ra_prof:: profile;
34
36
use test_utils:: tested_by;
35
37
36
38
use super :: {
39
+ primitive:: { FloatTy , IntTy } ,
37
40
traits:: { Guidance , Obligation , ProjectionPredicate , Solution } ,
38
41
ApplicationTy , InEnvironment , ProjectionTy , Substs , TraitEnvironment , TraitRef , Ty , TypeCtor ,
39
42
TypeWalk , Uncertain ,
40
43
} ;
41
44
use crate :: {
42
- code_model:: TypeAlias ,
43
- db:: HirDatabase ,
44
- expr:: { BindingAnnotation , Body , ExprId , PatId } ,
45
- ty:: infer:: diagnostics:: InferenceDiagnostic ,
46
- AssocItem , DefWithBody , FloatTy , Function , IntTy , Path , StructField , VariantDef ,
45
+ db:: HirDatabase , ty:: infer:: diagnostics:: InferenceDiagnostic , AssocItem , DefWithBody ,
46
+ VariantDef ,
47
47
} ;
48
48
49
49
macro_rules! ty_app {
@@ -121,11 +121,11 @@ pub struct TypeMismatch {
121
121
#[ derive( Clone , PartialEq , Eq , Debug , Default ) ]
122
122
pub struct InferenceResult {
123
123
/// For each method call expr, records the function it resolves to.
124
- method_resolutions : FxHashMap < ExprId , Function > ,
124
+ method_resolutions : FxHashMap < ExprId , FunctionId > ,
125
125
/// For each field access expr, records the field it resolves to.
126
- field_resolutions : FxHashMap < ExprId , StructField > ,
126
+ field_resolutions : FxHashMap < ExprId , StructFieldId > ,
127
127
/// For each field in record literal, records the field it resolves to.
128
- record_field_resolutions : FxHashMap < ExprId , StructField > ,
128
+ record_field_resolutions : FxHashMap < ExprId , StructFieldId > ,
129
129
/// For each struct literal, records the variant it resolves to.
130
130
variant_resolutions : FxHashMap < ExprOrPatId , VariantDef > ,
131
131
/// For each associated item record what it resolves to
@@ -137,13 +137,13 @@ pub struct InferenceResult {
137
137
}
138
138
139
139
impl InferenceResult {
140
- pub fn method_resolution ( & self , expr : ExprId ) -> Option < Function > {
140
+ pub fn method_resolution ( & self , expr : ExprId ) -> Option < FunctionId > {
141
141
self . method_resolutions . get ( & expr) . copied ( )
142
142
}
143
- pub fn field_resolution ( & self , expr : ExprId ) -> Option < StructField > {
143
+ pub fn field_resolution ( & self , expr : ExprId ) -> Option < StructFieldId > {
144
144
self . field_resolutions . get ( & expr) . copied ( )
145
145
}
146
- pub fn record_field_resolution ( & self , expr : ExprId ) -> Option < StructField > {
146
+ pub fn record_field_resolution ( & self , expr : ExprId ) -> Option < StructFieldId > {
147
147
self . record_field_resolutions . get ( & expr) . copied ( )
148
148
}
149
149
pub fn variant_resolution_for_expr ( & self , id : ExprId ) -> Option < VariantDef > {
@@ -164,7 +164,7 @@ impl InferenceResult {
164
164
pub ( crate ) fn add_diagnostics (
165
165
& self ,
166
166
db : & impl HirDatabase ,
167
- owner : Function ,
167
+ owner : FunctionId ,
168
168
sink : & mut DiagnosticSink ,
169
169
) {
170
170
self . diagnostics . iter ( ) . for_each ( |it| it. add_to ( db, owner, sink) )
@@ -243,11 +243,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
243
243
self . result . type_of_expr . insert ( expr, ty) ;
244
244
}
245
245
246
- fn write_method_resolution ( & mut self , expr : ExprId , func : Function ) {
246
+ fn write_method_resolution ( & mut self , expr : ExprId , func : FunctionId ) {
247
247
self . result . method_resolutions . insert ( expr, func) ;
248
248
}
249
249
250
- fn write_field_resolution ( & mut self , expr : ExprId , field : StructField ) {
250
+ fn write_field_resolution ( & mut self , expr : ExprId , field : StructFieldId ) {
251
251
self . result . field_resolutions . insert ( expr, field) ;
252
252
}
253
253
@@ -557,22 +557,22 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
557
557
self . infer_expr ( self . body . body_expr , & Expectation :: has_type ( self . return_ty . clone ( ) ) ) ;
558
558
}
559
559
560
- fn resolve_into_iter_item ( & self ) -> Option < TypeAlias > {
560
+ fn resolve_into_iter_item ( & self ) -> Option < TypeAliasId > {
561
561
let path = known:: std_iter_into_iterator ( ) ;
562
562
let trait_ = self . resolver . resolve_known_trait ( self . db , & path) ?;
563
- self . db . trait_data ( trait_) . associated_type_by_name ( & name:: ITEM_TYPE ) . map ( TypeAlias :: from )
563
+ self . db . trait_data ( trait_) . associated_type_by_name ( & name:: ITEM_TYPE )
564
564
}
565
565
566
- fn resolve_ops_try_ok ( & self ) -> Option < TypeAlias > {
566
+ fn resolve_ops_try_ok ( & self ) -> Option < TypeAliasId > {
567
567
let path = known:: std_ops_try ( ) ;
568
568
let trait_ = self . resolver . resolve_known_trait ( self . db , & path) ?;
569
- self . db . trait_data ( trait_) . associated_type_by_name ( & name:: OK_TYPE ) . map ( TypeAlias :: from )
569
+ self . db . trait_data ( trait_) . associated_type_by_name ( & name:: OK_TYPE )
570
570
}
571
571
572
- fn resolve_future_future_output ( & self ) -> Option < TypeAlias > {
572
+ fn resolve_future_future_output ( & self ) -> Option < TypeAliasId > {
573
573
let path = known:: std_future_future ( ) ;
574
574
let trait_ = self . resolver . resolve_known_trait ( self . db , & path) ?;
575
- self . db . trait_data ( trait_) . associated_type_by_name ( & name:: OUTPUT_TYPE ) . map ( TypeAlias :: from )
575
+ self . db . trait_data ( trait_) . associated_type_by_name ( & name:: OUTPUT_TYPE )
576
576
}
577
577
578
578
fn resolve_boxed_box ( & self ) -> Option < AdtId > {
@@ -696,9 +696,10 @@ impl Expectation {
696
696
}
697
697
698
698
mod diagnostics {
699
+ use hir_def:: { expr:: ExprId , FunctionId , HasSource , Lookup } ;
699
700
use hir_expand:: diagnostics:: DiagnosticSink ;
700
701
701
- use crate :: { db:: HirDatabase , diagnostics:: NoSuchField , expr :: ExprId , Function , HasSource } ;
702
+ use crate :: { db:: HirDatabase , diagnostics:: NoSuchField } ;
702
703
703
704
#[ derive( Debug , PartialEq , Eq , Clone ) ]
704
705
pub ( super ) enum InferenceDiagnostic {
@@ -709,13 +710,14 @@ mod diagnostics {
709
710
pub ( super ) fn add_to (
710
711
& self ,
711
712
db : & impl HirDatabase ,
712
- owner : Function ,
713
+ owner : FunctionId ,
713
714
sink : & mut DiagnosticSink ,
714
715
) {
715
716
match self {
716
717
InferenceDiagnostic :: NoSuchField { expr, field } => {
717
- let file = owner. source ( db) . file_id ;
718
- let field = owner. body_source_map ( db) . field_syntax ( * expr, * field) ;
718
+ let file = owner. lookup ( db) . source ( db) . file_id ;
719
+ let ( _, source_map) = db. body_with_source_map ( owner. into ( ) ) ;
720
+ let field = source_map. field_syntax ( * expr, * field) ;
719
721
sink. push ( NoSuchField { file, field } )
720
722
}
721
723
}
0 commit comments