@@ -428,14 +428,16 @@ impl Target {
428
428
#[ derive( Debug ) ]
429
429
struct ImportResolution {
430
430
/// Whether this resolution came from a `use` or a `pub use`. Note that this
431
- /// should *not* be used whenever resolution is being performed, this is
432
- /// only looked at for glob imports statements currently. Privacy testing
433
- /// occurs during a later phase of compilation.
431
+ /// should *not* be used whenever resolution is being performed. Privacy
432
+ /// testing occurs during a later phase of compilation.
434
433
is_public : bool ,
435
434
436
435
// The number of outstanding references to this name. When this reaches
437
436
// zero, outside modules can count on the targets being correct. Before
438
437
// then, all bets are off; future imports could override this name.
438
+ // Note that this is usually either 0 or 1 - shadowing is forbidden the only
439
+ // way outstanding_references is > 1 in a legal program is if the name is
440
+ // used in both namespaces.
439
441
outstanding_references : uint ,
440
442
441
443
/// The value that this `use` directive names, if there is one.
@@ -1144,8 +1146,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1144
1146
}
1145
1147
1146
1148
fn import_directive_subclass_to_string ( & mut self ,
1147
- subclass : ImportDirectiveSubclass )
1148
- -> String {
1149
+ subclass : ImportDirectiveSubclass )
1150
+ -> String {
1149
1151
match subclass {
1150
1152
SingleImport ( _, source) => {
1151
1153
token:: get_name ( source) . to_string ( )
@@ -1155,9 +1157,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1155
1157
}
1156
1158
1157
1159
fn import_path_to_string ( & mut self ,
1158
- names : & [ Name ] ,
1159
- subclass : ImportDirectiveSubclass )
1160
- -> String {
1160
+ names : & [ Name ] ,
1161
+ subclass : ImportDirectiveSubclass )
1162
+ -> String {
1161
1163
if names. is_empty ( ) {
1162
1164
self . import_directive_subclass_to_string ( subclass)
1163
1165
} else {
@@ -1238,7 +1240,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1238
1240
match import_directive. subclass {
1239
1241
SingleImport ( target, source) => {
1240
1242
resolution_result =
1241
- self . resolve_single_import ( & * module_,
1243
+ self . resolve_single_import ( & module_,
1242
1244
containing_module,
1243
1245
target,
1244
1246
source,
@@ -1247,7 +1249,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1247
1249
}
1248
1250
GlobImport => {
1249
1251
resolution_result =
1250
- self . resolve_glob_import ( & * module_,
1252
+ self . resolve_glob_import ( & module_,
1251
1253
containing_module,
1252
1254
import_directive,
1253
1255
lp) ;
@@ -1270,7 +1272,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1270
1272
// Decrement the count of unresolved globs if necessary. But only if
1271
1273
// the resolution result is indeterminate -- otherwise we'll stop
1272
1274
// processing imports here. (See the loop in
1273
- // resolve_imports_for_module.)
1275
+ // resolve_imports_for_module).
1274
1276
1275
1277
if !resolution_result. indeterminate ( ) {
1276
1278
match import_directive. subclass {
@@ -1301,16 +1303,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1301
1303
1302
1304
fn resolve_single_import ( & mut self ,
1303
1305
module_ : & Module ,
1304
- containing_module : Rc < Module > ,
1306
+ target_module : Rc < Module > ,
1305
1307
target : Name ,
1306
1308
source : Name ,
1307
1309
directive : & ImportDirective ,
1308
1310
lp : LastPrivate )
1309
- -> ResolveResult < ( ) > {
1311
+ -> ResolveResult < ( ) > {
1310
1312
debug ! ( "(resolving single import) resolving `{}` = `{}::{}` from \
1311
1313
`{}` id {}, last private {:?}",
1312
1314
token:: get_name( target) ,
1313
- self . module_to_string( & * containing_module ) ,
1315
+ self . module_to_string( & * target_module ) ,
1314
1316
token:: get_name( source) ,
1315
1317
self . module_to_string( module_) ,
1316
1318
directive. id,
@@ -1363,14 +1365,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1363
1365
// containing module, bail out. We don't know enough to be
1364
1366
// able to resolve this import.
1365
1367
1366
- if containing_module . glob_count . get ( ) > 0 {
1368
+ if target_module . glob_count . get ( ) > 0 {
1367
1369
debug ! ( "(resolving single import) unresolved glob; \
1368
1370
bailing out") ;
1369
1371
return Indeterminate ;
1370
1372
}
1371
1373
1372
1374
// Now search the exported imports within the containing module.
1373
- match containing_module . import_resolutions . borrow ( ) . get ( & source) {
1375
+ match target_module . import_resolutions . borrow ( ) . get ( & source) {
1374
1376
None => {
1375
1377
debug ! ( "(resolving single import) no import" ) ;
1376
1378
// The containing module definitely doesn't have an
@@ -1400,8 +1402,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1400
1402
return UnboundResult ;
1401
1403
}
1402
1404
1403
- match import_resolution.
1404
- target_for_namespace ( namespace) {
1405
+ match import_resolution. target_for_namespace ( namespace) {
1405
1406
None => {
1406
1407
return UnboundResult ;
1407
1408
}
@@ -1446,7 +1447,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1446
1447
1447
1448
}
1448
1449
Some ( _) => {
1449
- // If containing_module is the same module whose import we are resolving
1450
+ // If target_module is the same module whose import we are resolving
1450
1451
// and there it has an unresolved import with the same name as `source`,
1451
1452
// then the user is actually trying to import an item that is declared
1452
1453
// in the same scope
@@ -1458,7 +1459,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1458
1459
// In this case we continue as if we resolved the import and let the
1459
1460
// check_for_conflicts_between_imports_and_items call below handle
1460
1461
// the conflict
1461
- match ( module_. def_id . get ( ) , containing_module . def_id . get ( ) ) {
1462
+ match ( module_. def_id . get ( ) , target_module . def_id . get ( ) ) {
1462
1463
( Some ( id1) , Some ( id2) ) if id1 == id2 => {
1463
1464
if value_result. is_unknown ( ) {
1464
1465
value_result = UnboundResult ;
@@ -1479,29 +1480,26 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1479
1480
}
1480
1481
}
1481
1482
1482
- // If we didn't find a result in the type namespace, search the
1483
- // external modules.
1484
1483
let mut value_used_public = false ;
1485
1484
let mut type_used_public = false ;
1485
+
1486
+ // If we didn't find a result in the type namespace, search the
1487
+ // external modules.
1486
1488
match type_result {
1487
1489
BoundResult ( ..) => { }
1488
1490
_ => {
1489
- match containing_module. external_module_children . borrow_mut ( )
1490
- . get ( & source) . cloned ( ) {
1491
+ match target_module. external_module_children . borrow_mut ( ) . get ( & source) . cloned ( ) {
1491
1492
None => { } // Continue.
1492
1493
Some ( module) => {
1493
- debug ! ( "(resolving single import) found external \
1494
- module") ;
1494
+ debug ! ( "(resolving single import) found external module" ) ;
1495
1495
// track the module as used.
1496
1496
match module. def_id . get ( ) {
1497
1497
Some ( DefId { krate : kid, ..} ) => { self . used_crates . insert ( kid) ; } ,
1498
1498
_ => { }
1499
1499
}
1500
1500
let name_bindings =
1501
- Rc :: new ( Resolver :: create_name_bindings_from_module (
1502
- module) ) ;
1503
- type_result = BoundResult ( containing_module. clone ( ) ,
1504
- name_bindings) ;
1501
+ Rc :: new ( Resolver :: create_name_bindings_from_module ( module) ) ;
1502
+ type_result = BoundResult ( target_module. clone ( ) , name_bindings) ;
1505
1503
type_used_public = true ;
1506
1504
}
1507
1505
}
@@ -1511,6 +1509,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1511
1509
// We've successfully resolved the import. Write the results in.
1512
1510
let mut import_resolutions = module_. import_resolutions . borrow_mut ( ) ;
1513
1511
let import_resolution = & mut ( * import_resolutions) [ target] ;
1512
+
1514
1513
{
1515
1514
let mut check_and_write_import = |namespace, result : & _ , used_public : & mut bool | {
1516
1515
let namespace_name = match namespace {
@@ -1561,7 +1560,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1561
1560
if value_result. is_unbound ( ) && type_result. is_unbound ( ) {
1562
1561
let msg = format ! ( "There is no `{}` in `{}`" ,
1563
1562
token:: get_name( source) ,
1564
- self . module_to_string( & * containing_module ) ) ;
1563
+ self . module_to_string( & target_module ) ) ;
1565
1564
return Failed ( Some ( ( directive. span , msg) ) ) ;
1566
1565
}
1567
1566
let value_used_public = value_used_reexport || value_used_public;
@@ -1570,7 +1569,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1570
1569
assert ! ( import_resolution. outstanding_references >= 1 ) ;
1571
1570
import_resolution. outstanding_references -= 1 ;
1572
1571
1573
- // record what this import resolves to for later uses in documentation,
1572
+ // Record what this import resolves to for later uses in documentation,
1574
1573
// this may resolve to either a value or a type, but for documentation
1575
1574
// purposes it's good enough to just favor one over the other.
1576
1575
let value_def_and_priv = import_resolution. value_target . as_ref ( ) . map ( |target| {
@@ -1610,11 +1609,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1610
1609
1611
1610
// Resolves a glob import. Note that this function cannot fail; it either
1612
1611
// succeeds or bails out (as importing * from an empty module or a module
1613
- // that exports nothing is valid). containing_module is the module we are
1612
+ // that exports nothing is valid). target_module is the module we are
1614
1613
// actually importing, i.e., `foo` in `use foo::*`.
1615
1614
fn resolve_glob_import ( & mut self ,
1616
1615
module_ : & Module ,
1617
- containing_module : Rc < Module > ,
1616
+ target_module : Rc < Module > ,
1618
1617
import_directive : & ImportDirective ,
1619
1618
lp : LastPrivate )
1620
1619
-> ResolveResult < ( ) > {
@@ -1628,16 +1627,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1628
1627
1629
1628
// We must bail out if the node has unresolved imports of any kind
1630
1629
// (including globs).
1631
- if !( * containing_module ) . all_imports_resolved ( ) {
1630
+ if !( * target_module ) . all_imports_resolved ( ) {
1632
1631
debug ! ( "(resolving glob import) target module has unresolved \
1633
1632
imports; bailing out") ;
1634
1633
return Indeterminate ;
1635
1634
}
1636
1635
1637
- assert_eq ! ( containing_module . glob_count. get( ) , 0 ) ;
1636
+ assert_eq ! ( target_module . glob_count. get( ) , 0 ) ;
1638
1637
1639
1638
// Add all resolved imports from the containing module.
1640
- let import_resolutions = containing_module . import_resolutions . borrow ( ) ;
1639
+ let import_resolutions = target_module . import_resolutions . borrow ( ) ;
1641
1640
for ( ident, target_import_resolution) in & * import_resolutions {
1642
1641
debug ! ( "(resolving glob import) writing module resolution \
1643
1642
{} into `{}`",
@@ -1697,30 +1696,30 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1697
1696
}
1698
1697
1699
1698
// Add all children from the containing module.
1700
- build_reduced_graph:: populate_module_if_necessary ( self , & containing_module ) ;
1699
+ build_reduced_graph:: populate_module_if_necessary ( self , & target_module ) ;
1701
1700
1702
- for ( & name, name_bindings) in & * containing_module . children . borrow ( ) {
1701
+ for ( & name, name_bindings) in & * target_module . children . borrow ( ) {
1703
1702
self . merge_import_resolution ( module_,
1704
- containing_module . clone ( ) ,
1703
+ target_module . clone ( ) ,
1705
1704
import_directive,
1706
1705
name,
1707
1706
name_bindings. clone ( ) ) ;
1708
1707
1709
1708
}
1710
1709
1711
1710
// Add external module children from the containing module.
1712
- for ( & name, module) in & * containing_module . external_module_children . borrow ( ) {
1711
+ for ( & name, module) in & * target_module . external_module_children . borrow ( ) {
1713
1712
let name_bindings =
1714
1713
Rc :: new ( Resolver :: create_name_bindings_from_module ( module. clone ( ) ) ) ;
1715
1714
self . merge_import_resolution ( module_,
1716
- containing_module . clone ( ) ,
1715
+ target_module . clone ( ) ,
1717
1716
import_directive,
1718
1717
name,
1719
1718
name_bindings) ;
1720
1719
}
1721
1720
1722
1721
// Record the destination of this import
1723
- if let Some ( did) = containing_module . def_id . get ( ) {
1722
+ if let Some ( did) = target_module . def_id . get ( ) {
1724
1723
self . def_map . borrow_mut ( ) . insert ( id, PathResolution {
1725
1724
base_def : DefMod ( did) ,
1726
1725
last_private : lp,
0 commit comments