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