@@ -8,7 +8,7 @@ use crate::{diagnostics::SpannedHirAnalysisDb, HirAnalysisDb};
88/// Generic semantic identity at a source offset.
99/// This is compiler-facing and independent of any IDE layer types.
1010#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
11- pub enum SymbolIdentity < ' db > {
11+ pub enum SymbolKey < ' db > {
1212 Scope ( hir:: hir_def:: scope_graph:: ScopeId < ' db > ) ,
1313 EnumVariant ( hir:: hir_def:: EnumVariant < ' db > ) ,
1414 FuncParam ( hir:: hir_def:: ItemKind < ' db > , u16 ) ,
@@ -32,14 +32,14 @@ fn enclosing_func<'db>(
3232 None
3333}
3434
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 > > {
3636 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) ) ,
3939 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 )
4141 }
42- _ => res. as_scope ( db) . map ( SymbolIdentity :: Scope ) ,
42+ _ => res. as_scope ( db) . map ( SymbolKey :: Scope ) ,
4343 }
4444}
4545
@@ -50,24 +50,24 @@ pub fn identity_for_occurrence<'db>(
5050 db : & ' db dyn SpannedHirAnalysisDb ,
5151 top_mod : TopLevelMod < ' db > ,
5252 occ : & hir:: source_index:: OccurrencePayload < ' db > ,
53- ) -> Vec < SymbolIdentity < ' db > > {
53+ ) -> Vec < SymbolKey < ' db > > {
5454 use hir:: source_index:: OccurrencePayload as OP ;
5555
5656 match * occ {
5757 OP :: ItemHeaderName { scope, .. } => match scope {
5858 hir:: hir_def:: scope_graph:: ScopeId :: Item ( ItemKind :: Func ( f) ) => {
5959 if let Some ( fd) = crate :: ty:: func_def:: lower_func ( db, f) {
6060 if fd. is_method ( db) {
61- return vec ! [ SymbolIdentity :: Method ( fd) ] ;
61+ return vec ! [ SymbolKey :: Method ( fd) ] ;
6262 }
6363 }
64- vec ! [ SymbolIdentity :: Scope ( scope) ]
64+ vec ! [ SymbolKey :: Scope ( scope) ]
6565 }
6666 hir:: hir_def:: scope_graph:: ScopeId :: FuncParam ( item, idx) => {
67- vec ! [ SymbolIdentity :: FuncParam ( item, idx) ]
67+ vec ! [ SymbolKey :: FuncParam ( item, idx) ]
6868 }
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) ] ,
7171 } ,
7272 OP :: MethodName {
7373 scope,
@@ -100,19 +100,18 @@ pub fn identity_for_occurrence<'db>(
100100 MethodCandidate :: TraitMethod ( tm)
101101 | MethodCandidate :: NeedsConfirmation ( tm) => tm. method . 0 ,
102102 } ;
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 ( )
104107 }
105- Err ( MethodSelectionError :: AmbiguousInherentMethod ( methods) ) => methods
106- . iter ( )
107- . map ( |fd| SymbolIdentity :: Method ( * fd) )
108- . collect ( ) ,
109108 Err ( MethodSelectionError :: AmbiguousTraitMethod ( traits) ) => traits
110109 . iter ( )
111110 . filter_map ( |trait_def| {
112111 trait_def
113112 . methods ( db)
114113 . get ( & ident)
115- . map ( |tm| SymbolIdentity :: Method ( tm. 0 ) )
114+ . map ( |tm| SymbolKey :: Method ( tm. 0 ) )
116115 } )
117116 . collect ( ) ,
118117 Err ( _) => vec ! [ ] ,
@@ -133,9 +132,9 @@ pub fn identity_for_occurrence<'db>(
133132 if let Some ( bkey) = crate :: ty:: ty_check:: expr_binding_key_for_expr ( db, func, expr) {
134133 return vec ! [ match bkey {
135134 crate :: ty:: ty_check:: BindingKey :: FuncParam ( f, idx) => {
136- SymbolIdentity :: FuncParam ( ItemKind :: Func ( f) , idx)
135+ SymbolKey :: FuncParam ( ItemKind :: Func ( f) , idx)
137136 }
138- other => SymbolIdentity :: Local ( func, other) ,
137+ other => SymbolKey :: Local ( func, other) ,
139138 } ] ;
140139 }
141140 }
@@ -160,7 +159,7 @@ pub fn identity_for_occurrence<'db>(
160159 }
161160 OP :: PathPatSeg { body, pat, .. } => {
162161 if let Some ( func) = enclosing_func ( db, body. scope ( ) ) {
163- vec ! [ SymbolIdentity :: Local (
162+ vec ! [ SymbolKey :: Local (
164163 func,
165164 crate :: ty:: ty_check:: BindingKey :: LocalPat ( pat) ,
166165 ) ]
@@ -180,7 +179,7 @@ pub fn identity_for_occurrence<'db>(
180179 if let Some ( sc) =
181180 crate :: ty:: ty_check:: RecordLike :: from_ty ( recv_ty) . record_field_scope ( db, ident)
182181 {
183- return vec ! [ SymbolIdentity :: Scope ( sc) ] ;
182+ return vec ! [ SymbolKey :: Scope ( sc) ] ;
184183 }
185184 }
186185 vec ! [ ]
@@ -210,7 +209,7 @@ pub fn identity_for_occurrence<'db>(
210209 _ => None ,
211210 } ;
212211 if let Some ( target) = target {
213- return vec ! [ SymbolIdentity :: Scope ( target) ] ;
212+ return vec ! [ SymbolKey :: Scope ( target) ] ;
214213 }
215214 }
216215 }
@@ -230,7 +229,7 @@ pub fn identity_for_occurrence<'db>(
230229 {
231230 match nr. kind {
232231 crate :: name_resolution:: NameResKind :: Scope ( sc) => {
233- return vec ! [ SymbolIdentity :: Scope ( sc) ] ;
232+ return vec ! [ SymbolKey :: Scope ( sc) ] ;
234233 }
235234 crate :: name_resolution:: NameResKind :: Prim ( _) => { }
236235 }
@@ -329,7 +328,7 @@ fn find_ambiguous_candidates_for_path_seg<'db>(
329328 scope : ScopeId < ' db > ,
330329 path : PathId < ' db > ,
331330 seg_idx : usize ,
332- ) -> Vec < SymbolIdentity < ' db > > {
331+ ) -> Vec < SymbolKey < ' db > > {
333332 use crate :: name_resolution:: NameDomain ;
334333
335334 // Get the identifier from the path segment
@@ -367,14 +366,14 @@ fn find_ambiguous_candidates_for_path_seg<'db>(
367366 match bucket. pick ( domain) {
368367 Ok ( name_res) => {
369368 if let crate :: name_resolution:: NameResKind :: Scope ( sc) = name_res. kind {
370- candidates. push ( SymbolIdentity :: Scope ( sc) ) ;
369+ candidates. push ( SymbolKey :: Scope ( sc) ) ;
371370 }
372371 }
373372 Err ( crate :: name_resolution:: NameResolutionError :: Ambiguous ( ambiguous_candidates) ) => {
374373 // This is exactly what we want for ambiguous imports!
375374 for name_res in ambiguous_candidates {
376375 if let crate :: name_resolution:: NameResKind :: Scope ( sc) = name_res. kind {
377- candidates. push ( SymbolIdentity :: Scope ( sc) ) ;
376+ candidates. push ( SymbolKey :: Scope ( sc) ) ;
378377 }
379378 }
380379 }
0 commit comments