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