@@ -194,11 +194,11 @@ abstract class ItemNode extends Locatable {
194194 this = result .( ImplOrTraitItemNode ) .getAnItemInSelfScope ( )
195195 or
196196 name = "crate" and
197- this = result .( CrateItemNode ) .getARootModuleNode ( )
197+ this = result .( CrateItemNode ) .getASourceFile ( )
198198 or
199199 // todo: implement properly
200200 name = "$crate" and
201- result = any ( CrateItemNode crate | this = crate .getARootModuleNode ( ) ) .( Crate ) .getADependency * ( ) and
201+ result = any ( CrateItemNode crate | this = crate .getASourceFile ( ) ) .( Crate ) .getADependency * ( ) and
202202 result .( CrateItemNode ) .isPotentialDollarCrateTarget ( )
203203 }
204204
@@ -240,12 +240,6 @@ abstract private class ModuleLikeNode extends ItemNode {
240240 not mid instanceof ModuleLikeNode
241241 )
242242 }
243-
244- /**
245- * Holds if this is a root module, meaning either a source file or
246- * the entry module of a crate.
247- */
248- predicate isRoot ( ) { this instanceof SourceFileItemNode }
249243}
250244
251245private class SourceFileItemNode extends ModuleLikeNode , SourceFile {
@@ -267,16 +261,13 @@ private class SourceFileItemNode extends ModuleLikeNode, SourceFile {
267261
268262class CrateItemNode extends ItemNode instanceof Crate {
269263 /**
270- * Gets the module node that defines this crate.
271- *
272- * This is either a source file, when the crate is defined in source code,
273- * or a module, when the crate is defined in a dependency.
264+ * Gets the source file that defines this crate.
274265 */
275266 pragma [ nomagic]
276- ModuleLikeNode getModuleNode ( ) { result = super .getSourceFile ( ) }
267+ SourceFileItemNode getSourceFile ( ) { result = super .getSourceFile ( ) }
277268
278269 /**
279- * Gets a source file that belongs to this crate, if any .
270+ * Gets a source file that belongs to this crate.
280271 *
281272 * This is calculated as those source files that can be reached from the entry
282273 * file of this crate using zero or more `mod` imports, without going through
@@ -294,11 +285,6 @@ class CrateItemNode extends ItemNode instanceof Crate {
294285 )
295286 }
296287
297- /**
298- * Gets a root module node belonging to this crate.
299- */
300- ModuleLikeNode getARootModuleNode ( ) { result = this .getASourceFile ( ) }
301-
302288 pragma [ nomagic]
303289 predicate isPotentialDollarCrateTarget ( ) {
304290 exists ( string name , RelevantPath p |
@@ -710,7 +696,7 @@ private predicate modImport0(Module m, string name, Folder lookup) {
710696 // sibling import
711697 lookup = parent and
712698 (
713- m .getFile ( ) = any ( CrateItemNode c ) .getModuleNode ( ) . ( SourceFileItemNode ) .getFile ( )
699+ m .getFile ( ) = any ( CrateItemNode c ) .getSourceFile ( ) .getFile ( )
714700 or
715701 m .getFile ( ) .getBaseName ( ) = "mod.rs"
716702 )
@@ -798,25 +784,18 @@ private predicate fileImportEdge(Module mod, string name, ItemNode item) {
798784 */
799785pragma [ nomagic]
800786private predicate crateDefEdge ( CrateItemNode c , string name , ItemNode i ) {
801- i = c .getModuleNode ( ) .getASuccessorRec ( name ) and
787+ i = c .getSourceFile ( ) .getASuccessorRec ( name ) and
802788 not i instanceof Crate
803789}
804790
805791/**
806792 * Holds if `m` depends on crate `dep` named `name`.
807793 */
808794private predicate crateDependencyEdge ( ModuleLikeNode m , string name , CrateItemNode dep ) {
809- exists ( CrateItemNode c | dep = c .( Crate ) .getDependency ( name ) |
810- // entry module/entry source file
811- m = c .getModuleNode ( )
812- or
813- // entry/transitive source file
795+ exists ( CrateItemNode c |
796+ dep = c .( Crate ) .getDependency ( name ) and
814797 m = c .getASourceFile ( )
815798 )
816- or
817- // paths inside the crate graph use the name of the crate itself as prefix,
818- // although that is not valid in Rust
819- dep = any ( Crate c | name = c .getName ( ) and m = c .getSourceFile ( ) )
820799}
821800
822801private predicate useTreeDeclares ( UseTree tree , string name ) {
@@ -884,9 +863,9 @@ class RelevantPath extends Path {
884863
885864private predicate isModule ( ItemNode m ) { m instanceof Module }
886865
887- /** Holds if root module `root ` contains the module `m`. */
888- private predicate rootHasModule ( ItemNode root , ItemNode m ) =
889- doublyBoundedFastTC( hasChild / 2 , isRoot / 1 , isModule / 1 ) ( root , m )
866+ /** Holds if source file `source ` contains the module `m`. */
867+ private predicate rootHasModule ( SourceFileItemNode source , ItemNode m ) =
868+ doublyBoundedFastTC( hasChild / 2 , isSourceFile / 1 , isModule / 1 ) ( source , m )
890869
891870pragma [ nomagic]
892871private ItemNode getOuterScope ( ItemNode i ) {
@@ -939,14 +918,14 @@ private ItemNode getASuccessorFull(ItemNode pred, string name, Namespace ns) {
939918 ns = result .getNamespace ( )
940919}
941920
942- private predicate isRoot ( ItemNode root ) { root . ( ModuleLikeNode ) . isRoot ( ) }
921+ private predicate isSourceFile ( ItemNode source ) { source instanceof SourceFileItemNode }
943922
944923private predicate hasCratePath ( ItemNode i ) { any ( RelevantPath path ) .isCratePath ( _, i ) }
945924
946925private predicate hasChild ( ItemNode parent , ItemNode child ) { child .getImmediateParent ( ) = parent }
947926
948- private predicate rootHasCratePathTc ( ItemNode i1 , ItemNode i2 ) =
949- doublyBoundedFastTC( hasChild / 2 , isRoot / 1 , hasCratePath / 1 ) ( i1 , i2 )
927+ private predicate sourceFileHasCratePathTc ( ItemNode i1 , ItemNode i2 ) =
928+ doublyBoundedFastTC( hasChild / 2 , isSourceFile / 1 , hasCratePath / 1 ) ( i1 , i2 )
950929
951930/**
952931 * Holds if the unqualified path `p` references a keyword item named `name`, and
@@ -956,10 +935,10 @@ pragma[nomagic]
956935private predicate keywordLookup ( ItemNode encl , string name , Namespace ns , RelevantPath p ) {
957936 // For `($)crate`, jump directly to the root module
958937 exists ( ItemNode i | p .isCratePath ( name , i ) |
959- encl . ( ModuleLikeNode ) . isRoot ( ) and
938+ encl instanceof SourceFile and
960939 encl = i
961940 or
962- rootHasCratePathTc ( encl , i )
941+ sourceFileHasCratePathTc ( encl , i )
963942 )
964943 or
965944 name = [ "super" , "self" ] and
@@ -1176,8 +1155,8 @@ private module Debug {
11761155 private Locatable getRelevantLocatable ( ) {
11771156 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
11781157 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
1179- filepath .matches ( "%/test_logging .rs" ) and
1180- startline = 163
1158+ filepath .matches ( "%/main .rs" ) and
1159+ startline = 284
11811160 )
11821161 }
11831162
0 commit comments