@@ -636,6 +636,8 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
636636
637637 TraitItemNode resolveTraitTy ( ) { result = resolvePath ( this .getTraitPath ( ) ) }
638638
639+ predicate isBlanket ( ) { this .resolveSelfTy ( ) instanceof TypeParam }
640+
639641 override AssocItemNode getAnAssocItem ( ) { result = this .getADescendant ( ) }
640642
641643 override string getName ( ) { result = "(impl)" }
@@ -721,7 +723,7 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
721723 }
722724}
723725
724- final private class ImplTraitTypeReprItemNode extends TypeItemNode instanceof ImplTraitTypeRepr {
726+ final class ImplTraitTypeReprItemNode extends TypeItemNode instanceof ImplTraitTypeRepr {
725727 pragma [ nomagic]
726728 Path getABoundPath ( ) {
727729 result = super .getTypeBoundList ( ) .getABound ( ) .getTypeRepr ( ) .( PathTypeRepr ) .getPath ( )
@@ -1240,6 +1242,12 @@ private predicate crateDependency(SourceFileItemNode file, string name, CrateIte
12401242 exists ( CrateItemNode c | dep = c .( Crate ) .getDependency ( name ) | file = c .getASourceFile ( ) )
12411243}
12421244
1245+ pragma [ nomagic]
1246+ private predicate hasDeclOrDep ( SourceFileItemNode file , string name ) {
1247+ declaresDirectly ( file , TTypeNamespace ( ) , name ) or
1248+ crateDependency ( file , name , _)
1249+ }
1250+
12431251/**
12441252 * Holds if `file` depends on crate `dep` named `name`.
12451253 */
@@ -1253,8 +1261,7 @@ private predicate crateDependencyEdge(SourceFileItemNode file, string name, Crat
12531261 // a given file to its crate (for example, if the file is `mod` imported inside a macro that the
12541262 // extractor is unable to expand).
12551263 name = dep .getName ( ) and
1256- not declaresDirectly ( file , TTypeNamespace ( ) , name ) and
1257- not crateDependency ( file , name , _)
1264+ not hasDeclOrDep ( file , name )
12581265}
12591266
12601267private predicate useTreeDeclares ( UseTree tree , string name ) {
@@ -1425,24 +1432,56 @@ signature predicate relevantTraitVisibleSig(Element element, Trait trait);
14251432 * at a given element.
14261433 */
14271434module TraitIsVisible< relevantTraitVisibleSig / 2 relevantTraitVisible> {
1428- /** Holds if the trait might be looked up in `encl`. */
1429- private predicate traitLookup ( ItemNode encl , Element element , Trait trait ) {
1430- // lookup in immediately enclosing item
1431- relevantTraitVisible ( element , trait ) and
1432- encl .getADescendant ( ) = element
1435+ private newtype TNode =
1436+ TTrait ( Trait t ) { relevantTraitVisible ( _, t ) } or
1437+ TItemNode ( ItemNode i ) or
1438+ TElement ( Element e ) { relevantTraitVisible ( e , _) }
1439+
1440+ private predicate isTrait ( TNode n ) { n instanceof TTrait }
1441+
1442+ private predicate step ( TNode n1 , TNode n2 ) {
1443+ exists ( Trait t1 , ItemNode i2 |
1444+ n1 = TTrait ( t1 ) and
1445+ n2 = TItemNode ( i2 ) and
1446+ t1 = i2 .getASuccessor ( _, _)
1447+ )
14331448 or
1434- // lookup in an outer scope, but only if the trait is not declared in inner scope
1435- exists ( ItemNode mid |
1436- traitLookup ( mid , element , trait ) and
1437- not trait = mid .getASuccessor ( _, _) and
1438- encl = getOuterScope ( mid )
1449+ exists ( ItemNode i1 , ItemNode i2 |
1450+ n1 = TItemNode ( i1 ) and
1451+ n2 = TItemNode ( i2 ) and
1452+ i1 = getOuterScope ( i2 )
1453+ )
1454+ or
1455+ exists ( ItemNode i1 , Element e2 |
1456+ n1 = TItemNode ( i1 ) and
1457+ n2 = TElement ( e2 ) and
1458+ i1 .getADescendant ( ) = e2
1459+ )
1460+ }
1461+
1462+ private predicate isElement ( TNode n ) { n instanceof TElement }
1463+
1464+ private predicate traitIsVisibleTC ( TNode trait , TNode element ) =
1465+ doublyBoundedFastTC( step / 2 , isTrait / 1 , isElement / 1 ) ( trait , element )
1466+
1467+ pragma [ nomagic]
1468+ private predicate relevantTraitVisibleLift ( TNode trait , TElement element ) {
1469+ exists ( Trait t , Element e |
1470+ trait = TTrait ( t ) and
1471+ element = TElement ( e ) and
1472+ relevantTraitVisible ( e , t )
14391473 )
14401474 }
14411475
14421476 /** Holds if the trait `trait` is visible at `element`. */
14431477 pragma [ nomagic]
14441478 predicate traitIsVisible ( Element element , Trait trait ) {
1445- exists ( ItemNode encl | traitLookup ( encl , element , trait ) and trait = encl .getASuccessor ( _, _) )
1479+ exists ( TNode t , TNode e |
1480+ traitIsVisibleTC ( t , e ) and
1481+ relevantTraitVisibleLift ( t , e ) and
1482+ t = TTrait ( trait ) and
1483+ e = TElement ( element )
1484+ )
14461485 }
14471486}
14481487
0 commit comments