@@ -8,7 +8,7 @@ use crate::{diagnostics::SpannedHirAnalysisDb, HirAnalysisDb};
8
8
/// Generic semantic identity at a source offset.
9
9
/// This is compiler-facing and independent of any IDE layer types.
10
10
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
11
- pub enum SymbolIdentity < ' db > {
11
+ pub enum SymbolKey < ' db > {
12
12
Scope ( hir:: hir_def:: scope_graph:: ScopeId < ' db > ) ,
13
13
EnumVariant ( hir:: hir_def:: EnumVariant < ' db > ) ,
14
14
FuncParam ( hir:: hir_def:: ItemKind < ' db > , u16 ) ,
@@ -32,14 +32,14 @@ fn enclosing_func<'db>(
32
32
None
33
33
}
34
34
35
- fn map_path_res < ' db > ( db : & ' db dyn HirAnalysisDb , res : PathRes < ' db > ) -> Option < SymbolIdentity < ' db > > {
35
+ fn map_path_res < ' db > ( db : & ' db dyn HirAnalysisDb , res : PathRes < ' db > ) -> Option < SymbolKey < ' db > > {
36
36
match res {
37
- PathRes :: EnumVariant ( v) => Some ( SymbolIdentity :: EnumVariant ( v. variant ) ) ,
38
- PathRes :: FuncParam ( item, idx) => Some ( SymbolIdentity :: FuncParam ( item, idx) ) ,
37
+ PathRes :: EnumVariant ( v) => Some ( SymbolKey :: EnumVariant ( v. variant ) ) ,
38
+ PathRes :: FuncParam ( item, idx) => Some ( SymbolKey :: FuncParam ( item, idx) ) ,
39
39
PathRes :: Method ( ..) => {
40
- crate :: name_resolution:: method_func_def_from_res ( & res) . map ( SymbolIdentity :: Method )
40
+ crate :: name_resolution:: method_func_def_from_res ( & res) . map ( SymbolKey :: Method )
41
41
}
42
- _ => res. as_scope ( db) . map ( SymbolIdentity :: Scope ) ,
42
+ _ => res. as_scope ( db) . map ( SymbolKey :: Scope ) ,
43
43
}
44
44
}
45
45
@@ -50,24 +50,24 @@ pub fn identity_for_occurrence<'db>(
50
50
db : & ' db dyn SpannedHirAnalysisDb ,
51
51
top_mod : TopLevelMod < ' db > ,
52
52
occ : & hir:: source_index:: OccurrencePayload < ' db > ,
53
- ) -> Vec < SymbolIdentity < ' db > > {
53
+ ) -> Vec < SymbolKey < ' db > > {
54
54
use hir:: source_index:: OccurrencePayload as OP ;
55
55
56
56
match * occ {
57
57
OP :: ItemHeaderName { scope, .. } => match scope {
58
58
hir:: hir_def:: scope_graph:: ScopeId :: Item ( ItemKind :: Func ( f) ) => {
59
59
if let Some ( fd) = crate :: ty:: func_def:: lower_func ( db, f) {
60
60
if fd. is_method ( db) {
61
- return vec ! [ SymbolIdentity :: Method ( fd) ] ;
61
+ return vec ! [ SymbolKey :: Method ( fd) ] ;
62
62
}
63
63
}
64
- vec ! [ SymbolIdentity :: Scope ( scope) ]
64
+ vec ! [ SymbolKey :: Scope ( scope) ]
65
65
}
66
66
hir:: hir_def:: scope_graph:: ScopeId :: FuncParam ( item, idx) => {
67
- vec ! [ SymbolIdentity :: FuncParam ( item, idx) ]
67
+ vec ! [ SymbolKey :: FuncParam ( item, idx) ]
68
68
}
69
- hir:: hir_def:: scope_graph:: ScopeId :: Variant ( v) => vec ! [ SymbolIdentity :: EnumVariant ( v) ] ,
70
- other => vec ! [ SymbolIdentity :: Scope ( other) ] ,
69
+ hir:: hir_def:: scope_graph:: ScopeId :: Variant ( v) => vec ! [ SymbolKey :: EnumVariant ( v) ] ,
70
+ other => vec ! [ SymbolKey :: Scope ( other) ] ,
71
71
} ,
72
72
OP :: MethodName {
73
73
scope,
@@ -100,19 +100,18 @@ pub fn identity_for_occurrence<'db>(
100
100
MethodCandidate :: TraitMethod ( tm)
101
101
| MethodCandidate :: NeedsConfirmation ( tm) => tm. method . 0 ,
102
102
} ;
103
- vec ! [ SymbolIdentity :: Method ( fd) ]
103
+ vec ! [ SymbolKey :: Method ( fd) ]
104
+ }
105
+ Err ( MethodSelectionError :: AmbiguousInherentMethod ( methods) ) => {
106
+ methods. iter ( ) . map ( |fd| SymbolKey :: Method ( * fd) ) . collect ( )
104
107
}
105
- Err ( MethodSelectionError :: AmbiguousInherentMethod ( methods) ) => methods
106
- . iter ( )
107
- . map ( |fd| SymbolIdentity :: Method ( * fd) )
108
- . collect ( ) ,
109
108
Err ( MethodSelectionError :: AmbiguousTraitMethod ( traits) ) => traits
110
109
. iter ( )
111
110
. filter_map ( |trait_def| {
112
111
trait_def
113
112
. methods ( db)
114
113
. get ( & ident)
115
- . map ( |tm| SymbolIdentity :: Method ( tm. 0 ) )
114
+ . map ( |tm| SymbolKey :: Method ( tm. 0 ) )
116
115
} )
117
116
. collect ( ) ,
118
117
Err ( _) => vec ! [ ] ,
@@ -133,9 +132,9 @@ pub fn identity_for_occurrence<'db>(
133
132
if let Some ( bkey) = crate :: ty:: ty_check:: expr_binding_key_for_expr ( db, func, expr) {
134
133
return vec ! [ match bkey {
135
134
crate :: ty:: ty_check:: BindingKey :: FuncParam ( f, idx) => {
136
- SymbolIdentity :: FuncParam ( ItemKind :: Func ( f) , idx)
135
+ SymbolKey :: FuncParam ( ItemKind :: Func ( f) , idx)
137
136
}
138
- other => SymbolIdentity :: Local ( func, other) ,
137
+ other => SymbolKey :: Local ( func, other) ,
139
138
} ] ;
140
139
}
141
140
}
@@ -160,7 +159,7 @@ pub fn identity_for_occurrence<'db>(
160
159
}
161
160
OP :: PathPatSeg { body, pat, .. } => {
162
161
if let Some ( func) = enclosing_func ( db, body. scope ( ) ) {
163
- vec ! [ SymbolIdentity :: Local (
162
+ vec ! [ SymbolKey :: Local (
164
163
func,
165
164
crate :: ty:: ty_check:: BindingKey :: LocalPat ( pat) ,
166
165
) ]
@@ -180,7 +179,7 @@ pub fn identity_for_occurrence<'db>(
180
179
if let Some ( sc) =
181
180
crate :: ty:: ty_check:: RecordLike :: from_ty ( recv_ty) . record_field_scope ( db, ident)
182
181
{
183
- return vec ! [ SymbolIdentity :: Scope ( sc) ] ;
182
+ return vec ! [ SymbolKey :: Scope ( sc) ] ;
184
183
}
185
184
}
186
185
vec ! [ ]
@@ -210,7 +209,7 @@ pub fn identity_for_occurrence<'db>(
210
209
_ => None ,
211
210
} ;
212
211
if let Some ( target) = target {
213
- return vec ! [ SymbolIdentity :: Scope ( target) ] ;
212
+ return vec ! [ SymbolKey :: Scope ( target) ] ;
214
213
}
215
214
}
216
215
}
@@ -230,7 +229,7 @@ pub fn identity_for_occurrence<'db>(
230
229
{
231
230
match nr. kind {
232
231
crate :: name_resolution:: NameResKind :: Scope ( sc) => {
233
- return vec ! [ SymbolIdentity :: Scope ( sc) ] ;
232
+ return vec ! [ SymbolKey :: Scope ( sc) ] ;
234
233
}
235
234
crate :: name_resolution:: NameResKind :: Prim ( _) => { }
236
235
}
@@ -329,7 +328,7 @@ fn find_ambiguous_candidates_for_path_seg<'db>(
329
328
scope : ScopeId < ' db > ,
330
329
path : PathId < ' db > ,
331
330
seg_idx : usize ,
332
- ) -> Vec < SymbolIdentity < ' db > > {
331
+ ) -> Vec < SymbolKey < ' db > > {
333
332
use crate :: name_resolution:: NameDomain ;
334
333
335
334
// Get the identifier from the path segment
@@ -367,14 +366,14 @@ fn find_ambiguous_candidates_for_path_seg<'db>(
367
366
match bucket. pick ( domain) {
368
367
Ok ( name_res) => {
369
368
if let crate :: name_resolution:: NameResKind :: Scope ( sc) = name_res. kind {
370
- candidates. push ( SymbolIdentity :: Scope ( sc) ) ;
369
+ candidates. push ( SymbolKey :: Scope ( sc) ) ;
371
370
}
372
371
}
373
372
Err ( crate :: name_resolution:: NameResolutionError :: Ambiguous ( ambiguous_candidates) ) => {
374
373
// This is exactly what we want for ambiguous imports!
375
374
for name_res in ambiguous_candidates {
376
375
if let crate :: name_resolution:: NameResKind :: Scope ( sc) = name_res. kind {
377
- candidates. push ( SymbolIdentity :: Scope ( sc) ) ;
376
+ candidates. push ( SymbolKey :: Scope ( sc) ) ;
378
377
}
379
378
}
380
379
}
0 commit comments