@@ -1401,13 +1401,22 @@ class RelevantPath extends Path {
1401
1401
name = this .getText ( )
1402
1402
}
1403
1403
1404
+ /**
1405
+ * Holds if this is an unqualified path with the textual value `name` and
1406
+ * enclosing item `encl`.
1407
+ */
1404
1408
pragma [ nomagic]
1405
- predicate isCratePath ( string name , ItemNode encl ) {
1406
- name = [ "crate" , "$crate" ] and
1409
+ predicate isUnqualified ( string name , ItemNode encl ) {
1407
1410
this .isUnqualified ( name ) and
1408
1411
encl .getADescendant ( ) = this
1409
1412
}
1410
1413
1414
+ pragma [ nomagic]
1415
+ predicate isCratePath ( string name , ItemNode encl ) {
1416
+ name = [ "crate" , "$crate" ] and
1417
+ this .isUnqualified ( name , encl )
1418
+ }
1419
+
1411
1420
pragma [ nomagic]
1412
1421
predicate isDollarCrateQualifiedPath ( string name ) {
1413
1422
this .getQualifier ( ) .( RelevantPath ) .isCratePath ( "$crate" , _) and
@@ -1432,26 +1441,26 @@ private ItemNode getOuterScope(ItemNode i) {
1432
1441
}
1433
1442
1434
1443
/**
1435
- * Holds if the unqualified path `p ` references an item named `name`, and `name`
1436
- * may be looked up in the `ns` namespace inside enclosing item `encl `.
1444
+ * Holds if _some_ unqualified path in `encl ` references an item named `name`,
1445
+ * and `name` may be looked up in the `ns` namespace inside `ancestor `.
1437
1446
*/
1438
1447
pragma [ nomagic]
1439
- private predicate unqualifiedPathLookup ( ItemNode encl , string name , Namespace ns , RelevantPath p ) {
1448
+ private predicate unqualifiedPathLookup ( ItemNode ancestor , string name , Namespace ns , ItemNode encl ) {
1440
1449
// lookup in the immediately enclosing item
1441
- p .isUnqualified ( name ) and
1442
- encl . getADescendant ( ) = p and
1450
+ any ( RelevantPath p ) .isUnqualified ( name , encl ) and
1451
+ ancestor = encl and
1443
1452
exists ( ns ) and
1444
1453
not name = [ "crate" , "$crate" , "super" , "self" ]
1445
1454
or
1446
1455
// lookup in an outer scope, but only if the item is not declared in inner scope
1447
1456
exists ( ItemNode mid |
1448
- unqualifiedPathLookup ( mid , name , ns , p ) and
1457
+ unqualifiedPathLookup ( mid , name , ns , encl ) and
1449
1458
not declares ( mid , ns , name ) and
1450
1459
not (
1451
1460
name = "Self" and
1452
1461
mid = any ( ImplOrTraitItemNode i ) .getAnItemInSelfScope ( )
1453
1462
) and
1454
- encl = getOuterScope ( mid )
1463
+ ancestor = getOuterScope ( mid )
1455
1464
)
1456
1465
}
1457
1466
@@ -1477,29 +1486,31 @@ private predicate sourceFileHasCratePathTc(ItemNode i1, ItemNode i2) =
1477
1486
* `name` may be looked up inside enclosing item `encl`.
1478
1487
*/
1479
1488
pragma [ nomagic]
1480
- private predicate keywordLookup ( ItemNode encl , string name , RelevantPath p ) {
1489
+ private predicate keywordLookup ( ItemNode ancestor , string name , RelevantPath p ) {
1481
1490
// For `($)crate`, jump directly to the root module
1482
1491
exists ( ItemNode i | p .isCratePath ( name , i ) |
1483
- encl instanceof SourceFile and
1484
- encl = i
1492
+ ancestor instanceof SourceFile and
1493
+ ancestor = i
1485
1494
or
1486
- sourceFileHasCratePathTc ( encl , i )
1495
+ sourceFileHasCratePathTc ( ancestor , i )
1487
1496
)
1488
1497
or
1489
1498
name = [ "super" , "self" ] and
1490
- p .isUnqualified ( name ) and
1491
- encl .getADescendant ( ) = p
1499
+ p .isUnqualified ( name , ancestor )
1492
1500
}
1493
1501
1494
1502
pragma [ nomagic]
1495
1503
private ItemNode unqualifiedPathLookup ( RelevantPath p , Namespace ns , SuccessorKind kind ) {
1496
- exists ( ItemNode encl , string name |
1497
- result = getASuccessor ( encl , name , ns , kind , _) and
1504
+ exists ( ItemNode ancestor , string name |
1505
+ result = getASuccessor ( ancestor , pragma [ only_bind_into ] ( name ) , ns , kind , _) and
1498
1506
kind .isInternalOrBoth ( )
1499
1507
|
1500
- unqualifiedPathLookup ( encl , name , ns , p )
1508
+ exists ( ItemNode encl |
1509
+ unqualifiedPathLookup ( ancestor , name , ns , encl ) and
1510
+ p .isUnqualified ( pragma [ only_bind_into ] ( name ) , encl )
1511
+ )
1501
1512
or
1502
- keywordLookup ( encl , name , p ) and exists ( ns )
1513
+ keywordLookup ( ancestor , name , p ) and exists ( ns )
1503
1514
)
1504
1515
}
1505
1516
@@ -1880,10 +1891,13 @@ private module Debug {
1880
1891
}
1881
1892
1882
1893
predicate debugUnqualifiedPathLookup (
1883
- RelevantPath p , string name , Namespace ns , ItemNode encl , string path
1894
+ RelevantPath p , string name , Namespace ns , ItemNode ancestor , string path
1884
1895
) {
1885
1896
p = getRelevantLocatable ( ) and
1886
- unqualifiedPathLookup ( encl , name , ns , p ) and
1897
+ exists ( ItemNode encl |
1898
+ unqualifiedPathLookup ( encl , name , ns , ancestor ) and
1899
+ p .isUnqualified ( name , encl )
1900
+ ) and
1887
1901
path = p .toStringDebug ( )
1888
1902
}
1889
1903
0 commit comments