@@ -87,11 +87,6 @@ abstract class ItemNode extends Locatable {
87
87
/** Gets the `i`th type parameter of this item, if any. */
88
88
abstract TypeParam getTypeParam ( int i ) ;
89
89
90
- /** Holds if this item is declared as `pub`. */
91
- bindingset [ this ]
92
- pragma [ inline_late]
93
- predicate isPublic ( ) { exists ( this .getVisibility ( ) ) }
94
-
95
90
/** Gets an element that has this item as immediately enclosing item. */
96
91
pragma [ nomagic]
97
92
Element getADescendant ( ) {
@@ -207,6 +202,11 @@ abstract class ItemNode extends Locatable {
207
202
result .( CrateItemNode ) .isPotentialDollarCrateTarget ( )
208
203
}
209
204
205
+ pragma [ nomagic]
206
+ private predicate hasSourceFunction ( string name ) {
207
+ this .getASuccessorFull ( name ) .( Function ) .fromSource ( )
208
+ }
209
+
210
210
/** Gets a successor named `name` of this item, if any. */
211
211
pragma [ nomagic]
212
212
ItemNode getASuccessor ( string name ) {
@@ -219,7 +219,7 @@ abstract class ItemNode extends Locatable {
219
219
or
220
220
not result instanceof Function
221
221
or
222
- not this .getASuccessorFull ( name ) . ( Function ) . fromSource ( )
222
+ not this .hasSourceFunction ( name )
223
223
)
224
224
}
225
225
@@ -266,8 +266,6 @@ private class SourceFileItemNode extends ModuleLikeNode, SourceFile {
266
266
267
267
override Visibility getVisibility ( ) { none ( ) }
268
268
269
- override predicate isPublic ( ) { any ( ) }
270
-
271
269
override TypeParam getTypeParam ( int i ) { none ( ) }
272
270
}
273
271
@@ -330,8 +328,6 @@ class CrateItemNode extends ItemNode instanceof Crate {
330
328
331
329
override Visibility getVisibility ( ) { none ( ) }
332
330
333
- override predicate isPublic ( ) { any ( ) }
334
-
335
331
override TypeParam getTypeParam ( int i ) { none ( ) }
336
332
}
337
333
@@ -436,17 +432,17 @@ abstract class ImplOrTraitItemNode extends ItemNode {
436
432
437
433
pragma [ nomagic]
438
434
private TypeParamItemNode resolveTypeParamPathTypeRepr ( PathTypeRepr ptr ) {
439
- result = resolvePath ( ptr .getPath ( ) )
435
+ result = resolvePathFull ( ptr .getPath ( ) )
440
436
}
441
437
442
438
class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
443
439
Path getSelfPath ( ) { result = super .getSelfTy ( ) .( PathTypeRepr ) .getPath ( ) }
444
440
445
441
Path getTraitPath ( ) { result = super .getTrait ( ) .( PathTypeRepr ) .getPath ( ) }
446
442
447
- ItemNode resolveSelfTy ( ) { result = resolvePath ( this .getSelfPath ( ) ) }
443
+ ItemNode resolveSelfTy ( ) { result = resolvePathFull ( this .getSelfPath ( ) ) }
448
444
449
- TraitItemNode resolveTraitTy ( ) { result = resolvePath ( this .getTraitPath ( ) ) }
445
+ TraitItemNode resolveTraitTy ( ) { result = resolvePathFull ( this .getTraitPath ( ) ) }
450
446
451
447
pragma [ nomagic]
452
448
private TypeRepr getASelfTyArg ( ) {
@@ -560,7 +556,7 @@ class TraitItemNode extends ImplOrTraitItemNode instanceof Trait {
560
556
}
561
557
562
558
pragma [ nomagic]
563
- ItemNode resolveABound ( ) { result = resolvePath ( this .getABoundPath ( ) ) }
559
+ ItemNode resolveABound ( ) { result = resolvePathFull ( this .getABoundPath ( ) ) }
564
560
565
561
override AssocItemNode getAnAssocItem ( ) { result = super .getAssocItemList ( ) .getAnAssocItem ( ) }
566
562
@@ -634,7 +630,7 @@ class TypeParamItemNode extends ItemNode instanceof TypeParam {
634
630
}
635
631
636
632
pragma [ nomagic]
637
- ItemNode resolveABound ( ) { result = resolvePath ( this .getABoundPath ( ) ) }
633
+ ItemNode resolveABound ( ) { result = resolvePathFull ( this .getABoundPath ( ) ) }
638
634
639
635
/**
640
636
* Holds if this type parameter has a trait bound. Examples:
@@ -897,12 +893,6 @@ class RelevantPath extends Path {
897
893
this .getQualifier ( ) .( RelevantPath ) .isCratePath ( "$crate" , _) and
898
894
this .getText ( ) = name
899
895
}
900
-
901
- // TODO: Remove once the crate graph extractor generates publicly visible paths
902
- predicate requiresExtractorWorkaround ( ) {
903
- not this .fromSource ( ) and
904
- this = any ( RelevantPath p ) .getQualifier ( )
905
- }
906
896
}
907
897
908
898
private predicate isModule ( ItemNode m ) { m instanceof Module }
@@ -1056,8 +1046,14 @@ private predicate pathUsesNamespace(Path p, Namespace n) {
1056
1046
)
1057
1047
}
1058
1048
1049
+ /**
1050
+ * Gets the item that `path` resolves to, if any.
1051
+ *
1052
+ * Whenever `path` can resolve to both a function in source code and in library
1053
+ * code, both are included
1054
+ */
1059
1055
pragma [ nomagic]
1060
- private ItemNode resolvePath1 ( RelevantPath path ) {
1056
+ private ItemNode resolvePathFull ( RelevantPath path ) {
1061
1057
exists ( Namespace ns | result = resolvePath0 ( path , ns ) |
1062
1058
pathUsesNamespace ( path , ns )
1063
1059
or
@@ -1067,58 +1063,29 @@ private ItemNode resolvePath1(RelevantPath path) {
1067
1063
}
1068
1064
1069
1065
pragma [ nomagic]
1070
- private ItemNode resolvePathPrivate (
1071
- RelevantPath path , ModuleLikeNode itemParent , ModuleLikeNode pathParent
1072
- ) {
1073
- not path .requiresExtractorWorkaround ( ) and
1074
- result = resolvePath1 ( path ) and
1075
- itemParent = result .getImmediateParentModule ( ) and
1076
- not result .isPublic ( ) and
1077
- (
1078
- pathParent .getADescendant ( ) = path
1079
- or
1080
- pathParent = any ( ItemNode mid | path = mid .getADescendant ( ) ) .getImmediateParentModule ( )
1081
- )
1082
- }
1083
-
1084
- pragma [ nomagic]
1085
- private predicate isItemParent ( ModuleLikeNode itemParent ) {
1086
- exists ( resolvePathPrivate ( _, itemParent , _) )
1087
- }
1088
-
1089
- /**
1090
- * Gets a module that has access to private items defined inside `itemParent`.
1091
- *
1092
- * According to [The Rust Reference][1] this is either `itemParent` itself or any
1093
- * descendant of `itemParent`.
1094
- *
1095
- * [1]: https://doc.rust-lang.org/reference/visibility-and-privacy.html#r-vis.access
1096
- */
1097
- pragma [ nomagic]
1098
- private ModuleLikeNode getAPrivateVisibleModule ( ModuleLikeNode itemParent ) {
1099
- isItemParent ( itemParent ) and
1100
- result .getImmediateParentModule * ( ) = itemParent
1066
+ private predicate resolvesSourceFunction ( RelevantPath path ) {
1067
+ resolvePathFull ( path ) .( Function ) .fromSource ( )
1101
1068
}
1102
1069
1103
1070
/** Gets the item that `path` resolves to, if any. */
1104
1071
cached
1105
1072
ItemNode resolvePath ( RelevantPath path ) {
1106
- result = resolvePath1 ( path ) and
1073
+ result = resolvePathFull ( path ) and
1107
1074
(
1108
- result .isPublic ( )
1075
+ // when a function exists in both source code and in library code, it is because
1076
+ // we also extracted the source code as library code, and hence we only want
1077
+ // the function from source code
1078
+ result .fromSource ( )
1109
1079
or
1110
- path .requiresExtractorWorkaround ( )
1111
- )
1112
- or
1113
- exists ( ModuleLikeNode itemParent , ModuleLikeNode pathParent |
1114
- result = resolvePathPrivate ( path , itemParent , pathParent ) and
1115
- pathParent = getAPrivateVisibleModule ( itemParent )
1080
+ not result instanceof Function
1081
+ or
1082
+ not resolvesSourceFunction ( path )
1116
1083
)
1117
1084
}
1118
1085
1119
1086
pragma [ nomagic]
1120
1087
private ItemNode resolvePathQualifier ( RelevantPath path , string name ) {
1121
- result = resolvePath ( path .getQualifier ( ) ) and
1088
+ result = resolvePathFull ( path .getQualifier ( ) ) and
1122
1089
name = path .getText ( )
1123
1090
}
1124
1091
@@ -1164,7 +1131,7 @@ private ItemNode resolveUseTreeListItemQualifier(
1164
1131
pragma [ nomagic]
1165
1132
private ItemNode resolveUseTreeListItem ( Use use , UseTree tree ) {
1166
1133
tree = use .getUseTree ( ) and
1167
- result = resolvePath ( tree .getPath ( ) )
1134
+ result = resolvePathFull ( tree .getPath ( ) )
1168
1135
or
1169
1136
result = resolveUseTreeListItem ( use , tree , tree .getPath ( ) )
1170
1137
}
0 commit comments