@@ -655,6 +655,16 @@ private predicate fileModule(SourceFile f, string name, Folder folder) {
655
655
)
656
656
}
657
657
658
+ /**
659
+ * Gets the `Meta` of the module `m`'s [path attribute][1].
660
+ *
661
+ * [1]: https://doc.rust-lang.org/reference/items/modules.html#r-items.mod.outlined.path
662
+ */
663
+ private Meta getPathAttrMeta ( Module m ) {
664
+ result = m .getAnAttr ( ) .getMeta ( ) and
665
+ result .getPath ( ) .getText ( ) = "path"
666
+ }
667
+
658
668
/**
659
669
* Holds if `m` is a `mod name;` module declaration, where the corresponding
660
670
* module file needs to be looked up in `lookup` or one of its descandants.
@@ -663,12 +673,7 @@ private predicate modImport0(Module m, string name, Folder lookup) {
663
673
exists ( File f , Folder parent , string fileName |
664
674
f = m .getFile ( ) and
665
675
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
676
+ not exists ( getPathAttrMeta ( m ) ) and
672
677
name = m .getName ( ) .getText ( ) and
673
678
parent = f .getParentContainer ( ) and
674
679
fileName = f .getStem ( )
@@ -717,6 +722,16 @@ private predicate modImportNestedLookup(Module m, ModuleItemNode ancestor, Folde
717
722
)
718
723
}
719
724
725
+ private predicate pathAttrImport ( Folder f , Module m , string relativePath ) {
726
+ exists ( Meta meta |
727
+ f = m .getFile ( ) .getParentContainer ( ) and
728
+ meta = getPathAttrMeta ( m ) and
729
+ relativePath = meta .getExpr ( ) .( LiteralExpr ) .getTextValue ( ) .regexpCapture ( "\"(.+)\"" , 1 )
730
+ )
731
+ }
732
+
733
+ private predicate shouldAppend ( Folder f , string relativePath ) { pathAttrImport ( f , _, relativePath ) }
734
+
720
735
/** Holds if `m` is a `mod name;` item importing file `f`. */
721
736
private predicate fileImport ( Module m , SourceFile f ) {
722
737
exists ( string name , Folder parent |
@@ -730,6 +745,11 @@ private predicate fileImport(Module m, SourceFile f) {
730
745
// `m` is inside a nested module
731
746
modImportNestedLookup ( m , m , parent )
732
747
)
748
+ or
749
+ exists ( Folder folder , string relativePath |
750
+ pathAttrImport ( folder , m , relativePath ) and
751
+ f .getFile ( ) = Folder:: Append< shouldAppend / 2 > :: append ( folder , relativePath )
752
+ )
733
753
}
734
754
735
755
/**
0 commit comments