@@ -655,6 +655,11 @@ private predicate fileModule(SourceFile f, string name, Folder folder) {
655655 )
656656}
657657
658+ private Meta getPathAttrMeta ( Module m ) {
659+ result = m .getAnAttr ( ) .getMeta ( ) and
660+ result .getPath ( ) .getText ( ) = "path"
661+ }
662+
658663/**
659664 * Holds if `m` is a `mod name;` module declaration, where the corresponding
660665 * module file needs to be looked up in `lookup` or one of its descandants.
@@ -663,12 +668,7 @@ private predicate modImport0(Module m, string name, Folder lookup) {
663668 exists ( File f , Folder parent , string fileName |
664669 f = m .getFile ( ) and
665670 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
671+ not exists ( getPathAttrMeta ( m ) ) and
672672 name = m .getName ( ) .getText ( ) and
673673 parent = f .getParentContainer ( ) and
674674 fileName = f .getStem ( )
@@ -717,6 +717,16 @@ private predicate modImportNestedLookup(Module m, ModuleItemNode ancestor, Folde
717717 )
718718}
719719
720+ private predicate pathAttrImport ( Folder f , Module m , string relativePath ) {
721+ exists ( Meta meta |
722+ f = m .getFile ( ) .getParentContainer ( ) and
723+ meta = getPathAttrMeta ( m ) and
724+ relativePath = meta .getExpr ( ) .( LiteralExpr ) .getTextValue ( ) .regexpCapture ( "\"(.+)\"" , 1 )
725+ )
726+ }
727+
728+ private predicate append ( Folder f , string relativePath ) { pathAttrImport ( f , _, relativePath ) }
729+
720730/** Holds if `m` is a `mod name;` item importing file `f`. */
721731private predicate fileImport ( Module m , SourceFile f ) {
722732 exists ( string name , Folder parent |
@@ -730,6 +740,11 @@ private predicate fileImport(Module m, SourceFile f) {
730740 // `m` is inside a nested module
731741 modImportNestedLookup ( m , m , parent )
732742 )
743+ or
744+ exists ( Folder folder , string relativePath |
745+ pathAttrImport ( folder , m , relativePath ) and
746+ f .getFile ( ) = Folder:: Append< append / 2 > :: append ( folder , relativePath )
747+ )
733748}
734749
735750/**
0 commit comments