@@ -385,6 +385,10 @@ struct ImportResolution {
385
385
type_id : Cell < NodeId > ,
386
386
}
387
387
388
+ fn get < T : Clone > ( cell : & RefCell < T > ) -> T {
389
+ cell. borrow ( ) . clone ( )
390
+ }
391
+
388
392
impl ImportResolution {
389
393
fn new ( id : NodeId , is_public : bool ) -> ImportResolution {
390
394
ImportResolution {
@@ -400,8 +404,8 @@ impl ImportResolution {
400
404
fn target_for_namespace ( & self , namespace : Namespace )
401
405
-> Option < Target > {
402
406
match namespace {
403
- TypeNS => return self . type_target . get ( ) ,
404
- ValueNS => return self . value_target . get ( ) ,
407
+ TypeNS => return self . type_target . borrow ( ) . clone ( ) ,
408
+ ValueNS => return self . value_target . borrow ( ) . clone ( ) ,
405
409
}
406
410
}
407
411
@@ -546,7 +550,8 @@ impl NameBindings {
546
550
// Merges the module with the existing type def or creates a new one.
547
551
let module_ = @Module :: new ( parent_link, def_id, kind, external,
548
552
is_public) ;
549
- match self . type_def . get ( ) {
553
+ let type_def = self . type_def . borrow ( ) . clone ( ) ;
554
+ match type_def {
550
555
None => {
551
556
self . type_def . set ( Some ( TypeNsDef {
552
557
is_public : is_public,
@@ -574,7 +579,8 @@ impl NameBindings {
574
579
external : bool ,
575
580
is_public : bool ,
576
581
_sp : Span ) {
577
- match self . type_def . get ( ) {
582
+ let type_def = self . type_def . borrow ( ) . clone ( ) ;
583
+ match type_def {
578
584
None => {
579
585
let module = @Module :: new ( parent_link, def_id, kind,
580
586
external, is_public) ;
@@ -609,7 +615,8 @@ impl NameBindings {
609
615
/// Records a type definition.
610
616
fn define_type ( & self , def : Def , sp : Span , is_public : bool ) {
611
617
// Merges the type with the existing type def or creates a new one.
612
- match self . type_def . get ( ) {
618
+ let type_def = self . type_def . borrow ( ) . clone ( ) ;
619
+ match type_def {
613
620
None => {
614
621
self . type_def . set ( Some ( TypeNsDef {
615
622
module_def : None ,
@@ -662,17 +669,17 @@ impl NameBindings {
662
669
663
670
fn defined_in_namespace ( & self , namespace : Namespace ) -> bool {
664
671
match namespace {
665
- TypeNS => return self . type_def . get ( ) . is_some ( ) ,
666
- ValueNS => return self . value_def . get ( ) . is_some ( )
672
+ TypeNS => return self . type_def . borrow ( ) . is_some ( ) ,
673
+ ValueNS => return self . value_def . borrow ( ) . is_some ( )
667
674
}
668
675
}
669
676
670
677
fn defined_in_public_namespace ( & self , namespace : Namespace ) -> bool {
671
678
match namespace {
672
- TypeNS => match self . type_def . get ( ) {
679
+ TypeNS => match * self . type_def . borrow ( ) {
673
680
Some ( def) => def. is_public , None => false
674
681
} ,
675
- ValueNS => match self . value_def . get ( ) {
682
+ ValueNS => match * self . value_def . borrow ( ) {
676
683
Some ( def) => def. is_public , None => false
677
684
}
678
685
}
@@ -681,7 +688,7 @@ impl NameBindings {
681
688
fn def_for_namespace ( & self , namespace : Namespace ) -> Option < Def > {
682
689
match namespace {
683
690
TypeNS => {
684
- match self . type_def . get ( ) {
691
+ match * self . type_def . borrow ( ) {
685
692
None => None ,
686
693
Some ( type_def) => {
687
694
match type_def. type_def {
@@ -702,7 +709,7 @@ impl NameBindings {
702
709
}
703
710
}
704
711
ValueNS => {
705
- match self . value_def . get ( ) {
712
+ match * self . value_def . borrow ( ) {
706
713
None => None ,
707
714
Some ( value_def) => Some ( value_def. def )
708
715
}
@@ -714,13 +721,13 @@ impl NameBindings {
714
721
if self . defined_in_namespace ( namespace) {
715
722
match namespace {
716
723
TypeNS => {
717
- match self . type_def . get ( ) {
724
+ match * self . type_def . borrow ( ) {
718
725
None => None ,
719
726
Some ( type_def) => type_def. type_span
720
727
}
721
728
}
722
729
ValueNS => {
723
- match self . value_def . get ( ) {
730
+ match * self . value_def . borrow ( ) {
724
731
None => None ,
725
732
Some ( value_def) => value_def. value_span
726
733
}
@@ -1620,7 +1627,8 @@ impl<'a> Resolver<'a> {
1620
1627
match def {
1621
1628
DefMod ( def_id) | DefForeignMod ( def_id) | DefStruct ( def_id) |
1622
1629
DefTy ( def_id) => {
1623
- match child_name_bindings. type_def . get ( ) {
1630
+ let type_def = child_name_bindings. type_def . borrow ( ) . clone ( ) ;
1631
+ match type_def {
1624
1632
Some ( TypeNsDef { module_def : Some ( module_def) , .. } ) => {
1625
1633
debug ! ( "(building reduced graph for external crate) \
1626
1634
already created module") ;
@@ -1812,7 +1820,8 @@ impl<'a> Resolver<'a> {
1812
1820
// Process the static methods. First,
1813
1821
// create the module.
1814
1822
let type_module;
1815
- match child_name_bindings. type_def . get ( ) {
1823
+ let type_def = child_name_bindings. type_def . borrow ( ) . clone ( ) ;
1824
+ match type_def {
1816
1825
Some ( TypeNsDef {
1817
1826
module_def : Some ( module_def) ,
1818
1827
..
@@ -2421,7 +2430,7 @@ impl<'a> Resolver<'a> {
2421
2430
match type_result {
2422
2431
BoundResult ( target_module, name_bindings) => {
2423
2432
debug ! ( "(resolving single import) found type target: {:?}" ,
2424
- { name_bindings. type_def. get ( ) . unwrap( ) . type_def} ) ;
2433
+ { name_bindings. type_def. borrow ( ) . clone ( ) . unwrap( ) . type_def } ) ;
2425
2434
import_resolution. type_target . set (
2426
2435
Some ( Target :: new ( target_module, name_bindings) ) ) ;
2427
2436
import_resolution. type_id . set ( directive. id ) ;
@@ -2433,8 +2442,8 @@ impl<'a> Resolver<'a> {
2433
2442
}
2434
2443
}
2435
2444
2436
- if import_resolution. value_target . get ( ) . is_none ( ) &&
2437
- import_resolution. type_target . get ( ) . is_none ( ) {
2445
+ if import_resolution. value_target . borrow ( ) . is_none ( ) &&
2446
+ import_resolution. type_target . borrow ( ) . is_none ( ) {
2438
2447
let msg = format ! ( "unresolved import: there is no \
2439
2448
`{}` in `{}`",
2440
2449
token:: get_ident( source) ,
@@ -2452,7 +2461,7 @@ impl<'a> Resolver<'a> {
2452
2461
// record what this import resolves to for later uses in documentation,
2453
2462
// this may resolve to either a value or a type, but for documentation
2454
2463
// purposes it's good enough to just favor one over the other.
2455
- let value_private = match import_resolution. value_target . get ( ) {
2464
+ let value_private = match * import_resolution. value_target . borrow ( ) {
2456
2465
Some ( target) => {
2457
2466
let def = target. bindings . def_for_namespace ( ValueNS ) . unwrap ( ) ;
2458
2467
self . def_map . borrow_mut ( ) . insert ( directive. id , def) ;
@@ -2463,7 +2472,7 @@ impl<'a> Resolver<'a> {
2463
2472
// _exists is false.
2464
2473
None => None ,
2465
2474
} ;
2466
- let type_private = match import_resolution. type_target . get ( ) {
2475
+ let type_private = match * import_resolution. type_target . borrow ( ) {
2467
2476
Some ( target) => {
2468
2477
let def = target. bindings . def_for_namespace ( TypeNS ) . unwrap ( ) ;
2469
2478
self . def_map . borrow_mut ( ) . insert ( directive. id , def) ;
@@ -2513,7 +2522,7 @@ impl<'a> Resolver<'a> {
2513
2522
for ( ident, target_import_resolution) in import_resolutions. iter ( ) {
2514
2523
debug ! ( "(resolving glob import) writing module resolution \
2515
2524
{:?} into `{}`",
2516
- target_import_resolution. type_target. get ( ) . is_none( ) ,
2525
+ target_import_resolution. type_target. borrow ( ) . is_none( ) ,
2517
2526
self . module_to_str( module_) ) ;
2518
2527
2519
2528
if !target_import_resolution. is_public . get ( ) {
@@ -2529,9 +2538,9 @@ impl<'a> Resolver<'a> {
2529
2538
let new_import_resolution =
2530
2539
@ImportResolution :: new ( id, is_public) ;
2531
2540
new_import_resolution. value_target . set (
2532
- target_import_resolution. value_target . get ( ) ) ;
2541
+ get ( & target_import_resolution. value_target ) ) ;
2533
2542
new_import_resolution. type_target . set (
2534
- target_import_resolution. type_target . get ( ) ) ;
2543
+ get ( & target_import_resolution. type_target ) ) ;
2535
2544
2536
2545
import_resolutions. insert
2537
2546
( * ident, new_import_resolution) ;
@@ -2540,7 +2549,7 @@ impl<'a> Resolver<'a> {
2540
2549
// Merge the two import resolutions at a finer-grained
2541
2550
// level.
2542
2551
2543
- match target_import_resolution. value_target . get ( ) {
2552
+ match * target_import_resolution. value_target . borrow ( ) {
2544
2553
None => {
2545
2554
// Continue.
2546
2555
}
@@ -2549,7 +2558,7 @@ impl<'a> Resolver<'a> {
2549
2558
Some ( value_target) ) ;
2550
2559
}
2551
2560
}
2552
- match target_import_resolution. type_target . get ( ) {
2561
+ match * target_import_resolution. type_target . borrow ( ) {
2553
2562
None => {
2554
2563
// Continue.
2555
2564
}
@@ -2692,7 +2701,7 @@ impl<'a> Resolver<'a> {
2692
2701
Success ( ( target, used_proxy) ) => {
2693
2702
// Check to see whether there are type bindings, and, if
2694
2703
// so, whether there is a module within.
2695
- match target. bindings . type_def . get ( ) {
2704
+ match * target. bindings . type_def . borrow ( ) {
2696
2705
Some ( type_def) => {
2697
2706
match type_def. module_def {
2698
2707
None => {
@@ -3004,7 +3013,7 @@ impl<'a> Resolver<'a> {
3004
3013
match resolve_result {
3005
3014
Success ( ( target, _) ) => {
3006
3015
let bindings = & * target. bindings ;
3007
- match bindings. type_def . get ( ) {
3016
+ match * bindings. type_def . borrow ( ) {
3008
3017
Some ( type_def) => {
3009
3018
match type_def. module_def {
3010
3019
None => {
@@ -4526,8 +4535,8 @@ impl<'a> Resolver<'a> {
4526
4535
debug ! ( "(resolve bare identifier pattern) succeeded in \
4527
4536
finding {} at {:?}",
4528
4537
token:: get_ident( name) ,
4529
- target. bindings. value_def. get ( ) ) ;
4530
- match target. bindings . value_def . get ( ) {
4538
+ target. bindings. value_def. borrow ( ) ) ;
4539
+ match * target. bindings . value_def . borrow ( ) {
4531
4540
None => {
4532
4541
fail ! ( "resolved name in the value namespace to a \
4533
4542
set of name bindings with no def?!") ;
0 commit comments