@@ -655,6 +655,16 @@ private predicate fileModule(SourceFile f, string name, Folder folder) {
655655 )
656656}
657657
658+ /**
659+ * Gets the `Meta` of the module `m`'s [path attribute][1].
660+ *
661+ * [1]: https://doc.rust-lang.org/reference/items/modules.html#r-items.mod.outlined.path
662+ */
663+ private Meta getPathAttrMeta ( Module m ) {
664+ result = m .getAnAttr ( ) .getMeta ( ) and
665+ result .getPath ( ) .getText ( ) = "path"
666+ }
667+
658668/**
659669 * Holds if `m` is a `mod name;` module declaration, where the corresponding
660670 * module file needs to be looked up in `lookup` or one of its descandants.
@@ -663,12 +673,7 @@ private predicate modImport0(Module m, string name, Folder lookup) {
663673 exists ( File f , Folder parent , string fileName |
664674 f = m .getFile ( ) and
665675 not m .hasItemList ( ) and
666- // TODO: handle
667- // ```
668- // #[path = "foo.rs"]
669- // mod bar;
670- // ```
671- not m .getAnAttr ( ) .getMeta ( ) .getPath ( ) .getText ( ) = "path" and
676+ not exists ( getPathAttrMeta ( m ) ) and
672677 name = m .getName ( ) .getText ( ) and
673678 parent = f .getParentContainer ( ) and
674679 fileName = f .getStem ( )
@@ -717,6 +722,16 @@ private predicate modImportNestedLookup(Module m, ModuleItemNode ancestor, Folde
717722 )
718723}
719724
725+ private predicate pathAttrImport ( Folder f , Module m , string relativePath ) {
726+ exists ( Meta meta |
727+ f = m .getFile ( ) .getParentContainer ( ) and
728+ meta = getPathAttrMeta ( m ) and
729+ relativePath = meta .getExpr ( ) .( LiteralExpr ) .getTextValue ( ) .regexpCapture ( "\"(.+)\"" , 1 )
730+ )
731+ }
732+
733+ private predicate shouldAppend ( Folder f , string relativePath ) { pathAttrImport ( f , _, relativePath ) }
734+
720735/** Holds if `m` is a `mod name;` item importing file `f`. */
721736private predicate fileImport ( Module m , SourceFile f ) {
722737 exists ( string name , Folder parent |
@@ -730,6 +745,11 @@ private predicate fileImport(Module m, SourceFile f) {
730745 // `m` is inside a nested module
731746 modImportNestedLookup ( m , m , parent )
732747 )
748+ or
749+ exists ( Folder folder , string relativePath |
750+ pathAttrImport ( folder , m , relativePath ) and
751+ f .getFile ( ) = Folder:: Append< shouldAppend / 2 > :: append ( folder , relativePath )
752+ )
733753}
734754
735755/**
0 commit comments