@@ -995,11 +995,11 @@ pub struct Resolver<'a> {
995
995
// The idents for the primitive types.
996
996
primitive_type_table : PrimitiveTypeTable ,
997
997
998
- def_map : DefMap ,
999
- freevars : FreevarMap ,
998
+ pub def_map : DefMap ,
999
+ pub freevars : FreevarMap ,
1000
1000
freevars_seen : NodeMap < NodeMap < usize > > ,
1001
- export_map : ExportMap ,
1002
- trait_map : TraitMap ,
1001
+ pub export_map : ExportMap ,
1002
+ pub trait_map : TraitMap ,
1003
1003
1004
1004
// A map from nodes to modules, both normal (`mod`) modules and anonymous modules.
1005
1005
// Anonymous modules are pseudo-modules that are implicitly created around items
@@ -1022,14 +1022,14 @@ pub struct Resolver<'a> {
1022
1022
// so as to avoid printing duplicate errors
1023
1023
emit_errors : bool ,
1024
1024
1025
- make_glob_map : bool ,
1025
+ pub make_glob_map : bool ,
1026
1026
// Maps imports to the names of items actually imported (this actually maps
1027
1027
// all imports, but only glob imports are actually interesting).
1028
- glob_map : GlobMap ,
1028
+ pub glob_map : GlobMap ,
1029
1029
1030
1030
used_imports : HashSet < ( NodeId , Namespace ) > ,
1031
1031
used_crates : HashSet < CrateNum > ,
1032
- maybe_unused_trait_imports : NodeSet ,
1032
+ pub maybe_unused_trait_imports : NodeSet ,
1033
1033
1034
1034
privacy_errors : Vec < PrivacyError < ' a > > ,
1035
1035
@@ -3563,27 +3563,14 @@ fn err_path_resolution() -> PathResolution {
3563
3563
}
3564
3564
3565
3565
3566
- pub struct CrateMap {
3567
- pub def_map : RefCell < DefMap > ,
3568
- pub freevars : FreevarMap ,
3569
- pub maybe_unused_trait_imports : NodeSet ,
3570
- pub export_map : ExportMap ,
3571
- pub trait_map : TraitMap ,
3572
- pub glob_map : Option < GlobMap > ,
3573
- }
3574
-
3575
3566
#[ derive( PartialEq , Copy , Clone ) ]
3576
3567
pub enum MakeGlobMap {
3577
3568
Yes ,
3578
3569
No ,
3579
3570
}
3580
3571
3581
3572
/// Entry point to crate resolution.
3582
- pub fn resolve_crate < ' a > ( session : & ' a Session ,
3583
- krate : & ' a Crate ,
3584
- definitions : & ' a Definitions ,
3585
- make_glob_map : MakeGlobMap )
3586
- -> CrateMap {
3573
+ pub fn resolve_crate < ' a , ' b > ( resolver : & ' b mut Resolver < ' a > , krate : & ' b Crate ) {
3587
3574
// Currently, we ignore the name resolution data structures for
3588
3575
// the purposes of dependency tracking. Instead we will run name
3589
3576
// resolution and include its output in the hash of each item,
@@ -3592,42 +3579,23 @@ pub fn resolve_crate<'a>(session: &'a Session,
3592
3579
// resolution on those contents. Hopefully we'll push this back at
3593
3580
// some point.
3594
3581
3595
- let arenas = Resolver :: arenas ( ) ;
3596
- let mut resolver = create_resolver ( session, definitions, krate, make_glob_map, & arenas) ;
3597
-
3582
+ resolver. build_reduced_graph ( krate) ;
3583
+ resolve_imports:: resolve_imports ( resolver) ;
3598
3584
resolver. resolve_crate ( krate) ;
3599
3585
3600
- check_unused:: check_crate ( & mut resolver, krate) ;
3586
+ check_unused:: check_crate ( resolver, krate) ;
3601
3587
resolver. report_privacy_errors ( ) ;
3602
-
3603
- CrateMap {
3604
- def_map : RefCell :: new ( resolver. def_map ) ,
3605
- freevars : resolver. freevars ,
3606
- maybe_unused_trait_imports : resolver. maybe_unused_trait_imports ,
3607
- export_map : resolver. export_map ,
3608
- trait_map : resolver. trait_map ,
3609
- glob_map : if resolver. make_glob_map {
3610
- Some ( resolver. glob_map )
3611
- } else {
3612
- None
3613
- } ,
3614
- }
3615
3588
}
3616
3589
3617
- /// Builds a name resolution walker.
3618
- fn create_resolver < ' a > ( session : & ' a Session ,
3619
- definitions : & ' a Definitions ,
3620
- krate : & ' a Crate ,
3621
- make_glob_map : MakeGlobMap ,
3622
- arenas : & ' a ResolverArenas < ' a > )
3623
- -> Resolver < ' a > {
3624
- let mut resolver = Resolver :: new ( session, definitions, make_glob_map, arenas) ;
3625
-
3626
- resolver. build_reduced_graph ( krate) ;
3627
-
3628
- resolve_imports:: resolve_imports ( & mut resolver) ;
3629
-
3630
- resolver
3590
+ pub fn with_resolver < ' a , T , F > ( session : & ' a Session ,
3591
+ definitions : & ' a Definitions ,
3592
+ make_glob_map : MakeGlobMap ,
3593
+ f : F ) -> T
3594
+ where F : for < ' b > FnOnce ( Resolver < ' b > ) -> T ,
3595
+ {
3596
+ let arenas = Resolver :: arenas ( ) ;
3597
+ let resolver = Resolver :: new ( session, definitions, make_glob_map, & arenas) ;
3598
+ f ( resolver)
3631
3599
}
3632
3600
3633
3601
__build_diagnostic_array ! { librustc_resolve, DIAGNOSTICS }
0 commit comments