@@ -87,11 +87,6 @@ abstract class ItemNode extends Locatable {
8787 /** Gets the `i`th type parameter of this item, if any. */
8888 abstract TypeParam getTypeParam ( int i ) ;
8989
90- /** Holds if this item is declared as `pub`. */
91- bindingset [ this ]
92- pragma [ inline_late]
93- predicate isPublic ( ) { exists ( this .getVisibility ( ) ) }
94-
9590 /** Gets an element that has this item as immediately enclosing item. */
9691 pragma [ nomagic]
9792 Element getADescendant ( ) {
@@ -207,6 +202,11 @@ abstract class ItemNode extends Locatable {
207202 result .( CrateItemNode ) .isPotentialDollarCrateTarget ( )
208203 }
209204
205+ pragma [ nomagic]
206+ private predicate hasSourceFunction ( string name ) {
207+ this .getASuccessorFull ( name ) .( Function ) .fromSource ( )
208+ }
209+
210210 /** Gets a successor named `name` of this item, if any. */
211211 pragma [ nomagic]
212212 ItemNode getASuccessor ( string name ) {
@@ -219,7 +219,7 @@ abstract class ItemNode extends Locatable {
219219 or
220220 not result instanceof Function
221221 or
222- not this .getASuccessorFull ( name ) . ( Function ) . fromSource ( )
222+ not this .hasSourceFunction ( name )
223223 )
224224 }
225225
@@ -266,8 +266,6 @@ private class SourceFileItemNode extends ModuleLikeNode, SourceFile {
266266
267267 override Visibility getVisibility ( ) { none ( ) }
268268
269- override predicate isPublic ( ) { any ( ) }
270-
271269 override TypeParam getTypeParam ( int i ) { none ( ) }
272270}
273271
@@ -330,8 +328,6 @@ class CrateItemNode extends ItemNode instanceof Crate {
330328
331329 override Visibility getVisibility ( ) { none ( ) }
332330
333- override predicate isPublic ( ) { any ( ) }
334-
335331 override TypeParam getTypeParam ( int i ) { none ( ) }
336332}
337333
@@ -436,17 +432,17 @@ abstract class ImplOrTraitItemNode extends ItemNode {
436432
437433pragma [ nomagic]
438434private TypeParamItemNode resolveTypeParamPathTypeRepr ( PathTypeRepr ptr ) {
439- result = resolvePath ( ptr .getPath ( ) )
435+ result = resolvePathFull ( ptr .getPath ( ) )
440436}
441437
442438class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
443439 Path getSelfPath ( ) { result = super .getSelfTy ( ) .( PathTypeRepr ) .getPath ( ) }
444440
445441 Path getTraitPath ( ) { result = super .getTrait ( ) .( PathTypeRepr ) .getPath ( ) }
446442
447- ItemNode resolveSelfTy ( ) { result = resolvePath ( this .getSelfPath ( ) ) }
443+ ItemNode resolveSelfTy ( ) { result = resolvePathFull ( this .getSelfPath ( ) ) }
448444
449- TraitItemNode resolveTraitTy ( ) { result = resolvePath ( this .getTraitPath ( ) ) }
445+ TraitItemNode resolveTraitTy ( ) { result = resolvePathFull ( this .getTraitPath ( ) ) }
450446
451447 pragma [ nomagic]
452448 private TypeRepr getASelfTyArg ( ) {
@@ -560,7 +556,7 @@ class TraitItemNode extends ImplOrTraitItemNode instanceof Trait {
560556 }
561557
562558 pragma [ nomagic]
563- ItemNode resolveABound ( ) { result = resolvePath ( this .getABoundPath ( ) ) }
559+ ItemNode resolveABound ( ) { result = resolvePathFull ( this .getABoundPath ( ) ) }
564560
565561 override AssocItemNode getAnAssocItem ( ) { result = super .getAssocItemList ( ) .getAnAssocItem ( ) }
566562
@@ -634,7 +630,7 @@ class TypeParamItemNode extends ItemNode instanceof TypeParam {
634630 }
635631
636632 pragma [ nomagic]
637- ItemNode resolveABound ( ) { result = resolvePath ( this .getABoundPath ( ) ) }
633+ ItemNode resolveABound ( ) { result = resolvePathFull ( this .getABoundPath ( ) ) }
638634
639635 /**
640636 * Holds if this type parameter has a trait bound. Examples:
@@ -897,12 +893,6 @@ class RelevantPath extends Path {
897893 this .getQualifier ( ) .( RelevantPath ) .isCratePath ( "$crate" , _) and
898894 this .getText ( ) = name
899895 }
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- }
906896}
907897
908898private predicate isModule ( ItemNode m ) { m instanceof Module }
@@ -1056,8 +1046,14 @@ private predicate pathUsesNamespace(Path p, Namespace n) {
10561046 )
10571047}
10581048
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+ */
10591055pragma [ nomagic]
1060- private ItemNode resolvePath1 ( RelevantPath path ) {
1056+ private ItemNode resolvePathFull ( RelevantPath path ) {
10611057 exists ( Namespace ns | result = resolvePath0 ( path , ns ) |
10621058 pathUsesNamespace ( path , ns )
10631059 or
@@ -1067,58 +1063,29 @@ private ItemNode resolvePath1(RelevantPath path) {
10671063}
10681064
10691065pragma [ 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 ( )
11011068}
11021069
11031070/** Gets the item that `path` resolves to, if any. */
11041071cached
11051072ItemNode resolvePath ( RelevantPath path ) {
1106- result = resolvePath1 ( path ) and
1073+ result = resolvePathFull ( path ) and
11071074 (
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 ( )
11091079 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 )
11161083 )
11171084}
11181085
11191086pragma [ nomagic]
11201087private ItemNode resolvePathQualifier ( RelevantPath path , string name ) {
1121- result = resolvePath ( path .getQualifier ( ) ) and
1088+ result = resolvePathFull ( path .getQualifier ( ) ) and
11221089 name = path .getText ( )
11231090}
11241091
@@ -1164,7 +1131,7 @@ private ItemNode resolveUseTreeListItemQualifier(
11641131pragma [ nomagic]
11651132private ItemNode resolveUseTreeListItem ( Use use , UseTree tree ) {
11661133 tree = use .getUseTree ( ) and
1167- result = resolvePath ( tree .getPath ( ) )
1134+ result = resolvePathFull ( tree .getPath ( ) )
11681135 or
11691136 result = resolveUseTreeListItem ( use , tree , tree .getPath ( ) )
11701137}
0 commit comments