@@ -1666,39 +1666,51 @@ module TraitIsVisible<relevantTraitVisibleSig/2 relevantTraitVisible> {
1666
1666
}
1667
1667
}
1668
1668
1669
- pragma [ nomagic]
1670
- private predicate isDollarCrateSupportedMacroExpansion ( Path macroDefPath , AstNode expansion ) {
1671
- exists ( MacroCall mc |
1672
- expansion = mc .getMacroCallExpansion ( ) and
1673
- macroDefPath = mc .getPath ( )
1674
- )
1675
- or
1676
- exists ( ItemNode adt |
1677
- expansion = adt .( Adt ) .getDeriveMacroExpansion ( _) and
1678
- macroDefPath = adt .getAttr ( "derive" ) .getMeta ( ) .getPath ( )
1679
- )
1680
- }
1669
+ private module DollarCrateResolution {
1670
+ pragma [ nomagic]
1671
+ private predicate isDollarCrateSupportedMacroExpansion ( Path macroDefPath , AstNode expansion ) {
1672
+ exists ( MacroCall mc |
1673
+ expansion = mc .getMacroCallExpansion ( ) and
1674
+ macroDefPath = mc .getPath ( )
1675
+ )
1676
+ or
1677
+ exists ( ItemNode adt |
1678
+ expansion = adt .( Adt ) .getDeriveMacroExpansion ( _) and
1679
+ macroDefPath = adt .getAttr ( "derive" ) .getMeta ( ) .getPath ( )
1680
+ )
1681
+ }
1681
1682
1682
- pragma [ nomagic]
1683
- predicate isInDollarCrateSupportedMacroExpansion ( File macroDefFile , AstNode n ) {
1684
- exists ( Path macroDefPath |
1685
- isDollarCrateSupportedMacroExpansion ( macroDefPath , n ) and
1686
- macroDefFile = resolvePathCand ( macroDefPath ) .getFile ( )
1687
- )
1688
- or
1689
- isInDollarCrateSupportedMacroExpansion ( macroDefFile , n .getParentNode ( ) )
1690
- }
1683
+ private predicate hasParent ( AstNode child , AstNode parent ) { parent = child .getParentNode ( ) }
1691
1684
1692
- /**
1693
- * Holds if `n` is a `$crate` path, and it may resolve to `crate`.
1694
- *
1695
- * The reason why we cannot be sure is that we need to consider all ancestor macro
1696
- * calls.
1697
- */
1698
- pragma [ nomagic]
1699
- predicate resolveDollarCrate ( RelevantPath p , CrateItemNode crate ) {
1700
- p .isDollarCrate ( ) and
1701
- isInDollarCrateSupportedMacroExpansion ( crate .getASourceFile ( ) .getFile ( ) , p )
1685
+ private predicate isDollarCrateSupportedMacroExpansion ( AstNode expansion ) {
1686
+ isDollarCrateSupportedMacroExpansion ( _, expansion )
1687
+ }
1688
+
1689
+ private predicate isDollarCratePath ( RelevantPath p ) { p .isDollarCrate ( ) }
1690
+
1691
+ private predicate isInDollarCrateMacroExpansion ( RelevantPath p , AstNode expansion ) =
1692
+ doublyBoundedFastTC( hasParent / 2 , isDollarCratePath / 1 , isDollarCrateSupportedMacroExpansion / 1 ) ( p ,
1693
+ expansion )
1694
+
1695
+ pragma [ nomagic]
1696
+ private predicate isInDollarCrateMacroExpansionFromFile ( File macroDefFile , RelevantPath p ) {
1697
+ exists ( Path macroDefPath , AstNode expansion |
1698
+ isDollarCrateSupportedMacroExpansion ( macroDefPath , expansion ) and
1699
+ isInDollarCrateMacroExpansion ( p , expansion ) and
1700
+ macroDefFile = resolvePathCand ( macroDefPath ) .getFile ( )
1701
+ )
1702
+ }
1703
+
1704
+ /**
1705
+ * Holds if `p` is a `$crate` path, and it may resolve to `crate`.
1706
+ *
1707
+ * The reason why we cannot be sure is that we need to consider all ancestor macro
1708
+ * calls.
1709
+ */
1710
+ pragma [ nomagic]
1711
+ predicate resolveDollarCrate ( RelevantPath p , CrateItemNode crate ) {
1712
+ isInDollarCrateMacroExpansionFromFile ( crate .getASourceFile ( ) .getFile ( ) , p )
1713
+ }
1702
1714
}
1703
1715
1704
1716
pragma [ nomagic]
@@ -1713,7 +1725,7 @@ private ItemNode resolvePathCand0(RelevantPath path, Namespace ns) {
1713
1725
else result = res
1714
1726
)
1715
1727
or
1716
- resolveDollarCrate ( path , result ) and
1728
+ DollarCrateResolution :: resolveDollarCrate ( path , result ) and
1717
1729
ns = result .getNamespace ( )
1718
1730
or
1719
1731
result = resolvePathCandQualified ( _, _, path , ns )
0 commit comments