@@ -653,6 +653,11 @@ private predicate fileModule(SourceFile f, string name, Folder folder) {
653653 )
654654}
655655
656+ private Meta getPathAttrMeta ( Module m ) {
657+ result = m .getAnAttr ( ) .getMeta ( ) and
658+ result .getPath ( ) .getText ( ) = "path"
659+ }
660+
656661/**
657662 * Holds if `m` is a `mod name;` module declaration, where the corresponding
658663 * module file needs to be looked up in `lookup` or one of its descandants.
@@ -661,12 +666,7 @@ private predicate modImport0(Module m, string name, Folder lookup) {
661666 exists ( File f , Folder parent , string fileName |
662667 f = m .getFile ( ) and
663668 not m .hasItemList ( ) and
664- // TODO: handle
665- // ```
666- // #[path = "foo.rs"]
667- // mod bar;
668- // ```
669- not m .getAnAttr ( ) .getMeta ( ) .getPath ( ) .getText ( ) = "path" and
669+ not exists ( getPathAttrMeta ( m ) ) and
670670 name = m .getName ( ) .getText ( ) and
671671 parent = f .getParentContainer ( ) and
672672 fileName = f .getStem ( )
@@ -715,6 +715,16 @@ private predicate modImportNestedLookup(Module m, ModuleItemNode ancestor, Folde
715715 )
716716}
717717
718+ private predicate pathAttrImport ( Folder f , Module m , string relativePath ) {
719+ exists ( Meta meta |
720+ f = m .getFile ( ) .getParentContainer ( ) and
721+ meta = getPathAttrMeta ( m ) and
722+ relativePath = meta .getExpr ( ) .( LiteralExpr ) .getTextValue ( ) .regexpCapture ( "\"(.+)\"" , 1 )
723+ )
724+ }
725+
726+ private predicate append ( Folder f , string relativePath ) { pathAttrImport ( f , _, relativePath ) }
727+
718728/** Holds if `m` is a `mod name;` item importing file `f`. */
719729private predicate fileImport ( Module m , SourceFile f ) {
720730 exists ( string name , Folder parent |
@@ -728,6 +738,11 @@ private predicate fileImport(Module m, SourceFile f) {
728738 // `m` is inside a nested module
729739 modImportNestedLookup ( m , m , parent )
730740 )
741+ or
742+ exists ( Folder folder , string relativePath |
743+ pathAttrImport ( folder , m , relativePath ) and
744+ f .getFile ( ) = FolderAppend< append / 2 > :: append ( folder , relativePath )
745+ )
731746}
732747
733748/**
0 commit comments