@@ -654,6 +654,11 @@ private predicate fileModule(SourceFile f, string name, Folder folder) {
654
654
)
655
655
}
656
656
657
+ private Meta getPathAttrMeta ( Module m ) {
658
+ result = m .getAnAttr ( ) .getMeta ( ) and
659
+ result .getPath ( ) .getText ( ) = "path"
660
+ }
661
+
657
662
/**
658
663
* Holds if `m` is a `mod name;` module declaration, where the corresponding
659
664
* 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) {
662
667
exists ( File f , Folder parent , string fileName |
663
668
f = m .getFile ( ) and
664
669
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
671
671
name = m .getName ( ) .getText ( ) and
672
672
parent = f .getParentContainer ( ) and
673
673
fileName = f .getStem ( )
@@ -716,6 +716,16 @@ private predicate modImportNestedLookup(Module m, ModuleItemNode ancestor, Folde
716
716
)
717
717
}
718
718
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
+
719
729
/** Holds if `m` is a `mod name;` item importing file `f`. */
720
730
private predicate fileImport ( Module m , SourceFile f ) {
721
731
exists ( string name , Folder parent |
@@ -729,6 +739,11 @@ private predicate fileImport(Module m, SourceFile f) {
729
739
// `m` is inside a nested module
730
740
modImportNestedLookup ( m , m , parent )
731
741
)
742
+ or
743
+ exists ( Folder folder , string relativePath |
744
+ pathAttrImport ( folder , m , relativePath ) and
745
+ f .getFile ( ) = FolderAppend< append / 2 > :: append ( folder , relativePath )
746
+ )
732
747
}
733
748
734
749
/**
0 commit comments