@@ -172,9 +172,14 @@ abstract class ItemNode extends Locatable {
172
172
result = this .( TypeParamItemNode ) .resolveABound ( ) .getASuccessorRec ( name ) .( AssocItemNode )
173
173
}
174
174
175
- /** Gets a successor named `name` of this item, if any. */
175
+ /**
176
+ * Gets a successor named `name` of this item, if any.
177
+ *
178
+ * Whenever a function exists in both source code and in library code,
179
+ * both are included
180
+ */
176
181
cached
177
- ItemNode getASuccessor ( string name ) {
182
+ ItemNode getASuccessorFull ( string name ) {
178
183
Stages:: PathResolutionStage:: ref ( ) and
179
184
result = this .getASuccessorRec ( name )
180
185
or
@@ -202,6 +207,22 @@ abstract class ItemNode extends Locatable {
202
207
result .( CrateItemNode ) .isPotentialDollarCrateTarget ( )
203
208
}
204
209
210
+ /** Gets a successor named `name` of this item, if any. */
211
+ pragma [ nomagic]
212
+ ItemNode getASuccessor ( string name ) {
213
+ result = this .getASuccessorFull ( name ) and
214
+ (
215
+ // when a function exists in both source code and in library code, it is because
216
+ // we also extracted the source code as library code, and hence we only want
217
+ // the function from source code
218
+ result .fromSource ( )
219
+ or
220
+ not result instanceof Function
221
+ or
222
+ not this .getASuccessorFull ( name ) .( Function ) .fromSource ( )
223
+ )
224
+ }
225
+
205
226
/** Gets the location of this item. */
206
227
Location getLocation ( ) { result = super .getLocation ( ) }
207
228
}
@@ -234,7 +255,7 @@ abstract private class ModuleLikeNode extends ItemNode {
234
255
private class SourceFileItemNode extends ModuleLikeNode , SourceFile {
235
256
pragma [ nomagic]
236
257
ModuleLikeNode getSuper ( ) {
237
- result = any ( ModuleItemNode mod | fileImport ( mod , this ) ) .getASuccessor ( "super" )
258
+ result = any ( ModuleItemNode mod | fileImport ( mod , this ) ) .getASuccessorFull ( "super" )
238
259
}
239
260
240
261
override string getName ( ) { result = "(source file)" }
@@ -297,7 +318,7 @@ class CrateItemNode extends ItemNode instanceof Crate {
297
318
predicate isPotentialDollarCrateTarget ( ) {
298
319
exists ( string name , RelevantPath p |
299
320
p .isDollarCrateQualifiedPath ( name ) and
300
- exists ( this .getASuccessor ( name ) )
321
+ exists ( this .getASuccessorFull ( name ) )
301
322
)
302
323
}
303
324
@@ -328,10 +349,8 @@ private class ConstItemNode extends AssocItemNode instanceof Const {
328
349
or
329
350
// for trait items from library code, we do not currently know if they
330
351
// have default implementations or not, so we assume they do
331
- exists ( TraitItemNode t |
332
- this = t .getAnAssocItem ( ) and
333
- not this .fromSource ( )
334
- )
352
+ not this .fromSource ( ) and
353
+ this = any ( TraitItemNode t ) .getAnAssocItem ( )
335
354
}
336
355
337
356
override Namespace getNamespace ( ) { result .isValue ( ) }
@@ -373,10 +392,8 @@ class FunctionItemNode extends AssocItemNode instanceof Function {
373
392
or
374
393
// for trait items from library code, we do not currently know if they
375
394
// have default implementations or not, so we assume they do
376
- exists ( TraitItemNode t |
377
- this = t .getAnAssocItem ( ) and
378
- not this .fromSource ( )
379
- )
395
+ not this .fromSource ( ) and
396
+ this = any ( TraitItemNode t ) .getAnAssocItem ( )
380
397
}
381
398
382
399
override Namespace getNamespace ( ) { result .isValue ( ) }
@@ -940,8 +957,8 @@ private predicate unqualifiedPathLookup(ItemNode encl, string name, Namespace ns
940
957
}
941
958
942
959
pragma [ nomagic]
943
- private ItemNode getASuccessor ( ItemNode pred , string name , Namespace ns ) {
944
- result = pred .getASuccessor ( name ) and
960
+ private ItemNode getASuccessorFull ( ItemNode pred , string name , Namespace ns ) {
961
+ result = pred .getASuccessorFull ( name ) and
945
962
ns = result .getNamespace ( )
946
963
}
947
964
@@ -978,7 +995,7 @@ private predicate keywordLookup(ItemNode encl, string name, Namespace ns, Releva
978
995
979
996
pragma [ nomagic]
980
997
private ItemNode unqualifiedPathLookup ( RelevantPath p , Namespace ns ) {
981
- exists ( ItemNode encl , string name | result = getASuccessor ( encl , name , ns ) |
998
+ exists ( ItemNode encl , string name | result = getASuccessorFull ( encl , name , ns ) |
982
999
unqualifiedPathLookup ( encl , name , ns , p )
983
1000
or
984
1001
keywordLookup ( encl , name , ns , p )
@@ -1002,7 +1019,7 @@ private ItemNode resolvePath0(RelevantPath path, Namespace ns) {
1002
1019
or
1003
1020
exists ( ItemNode q , string name |
1004
1021
q = resolvePathQualifier ( path , name ) and
1005
- result = getASuccessor ( q , name , ns )
1022
+ result = getASuccessorFull ( q , name , ns )
1006
1023
)
1007
1024
or
1008
1025
result = resolveUseTreeListItem ( _, _, path ) and
@@ -1127,12 +1144,12 @@ private ItemNode resolveUseTreeListItem(Use use, UseTree tree, RelevantPath path
1127
1144
mid = resolveUseTreeListItem ( use , midTree ) and
1128
1145
tree = midTree .getUseTreeList ( ) .getAUseTree ( ) and
1129
1146
isUseTreeSubPathUnqualified ( tree , path , pragma [ only_bind_into ] ( name ) ) and
1130
- result = mid .getASuccessor ( pragma [ only_bind_into ] ( name ) )
1147
+ result = mid .getASuccessorFull ( pragma [ only_bind_into ] ( name ) )
1131
1148
)
1132
1149
or
1133
1150
exists ( ItemNode q , string name |
1134
1151
q = resolveUseTreeListItemQualifier ( use , tree , path , name ) and
1135
- result = q .getASuccessor ( name )
1152
+ result = q .getASuccessorFull ( name )
1136
1153
)
1137
1154
}
1138
1155
@@ -1162,7 +1179,7 @@ private predicate useImportEdge(Use use, string name, ItemNode item) {
1162
1179
then
1163
1180
exists ( ItemNode encl , Namespace ns |
1164
1181
encl .getADescendant ( ) = use and
1165
- item = getASuccessor ( used , name , ns ) and
1182
+ item = getASuccessorFull ( used , name , ns ) and
1166
1183
// glob imports can be shadowed
1167
1184
not declares ( encl , ns , name ) and
1168
1185
not name = [ "super" , "self" , "Self" , "$crate" , "crate" ]
0 commit comments