@@ -980,7 +980,7 @@ pub struct Resolver<'a> {
980980 //
981981 // There will be an anonymous module created around `g` with the ID of the
982982 // entry block for `f`.
983- module_map : NodeMap < Module < ' a > > ,
983+ pub module_map : NodeMap < Module < ' a > > ,
984984
985985 // Whether or not to print error messages. Can be set to true
986986 // when getting additional info for error message suggestions,
@@ -2686,6 +2686,33 @@ impl<'a> Resolver<'a> {
26862686 rs
26872687 }
26882688
2689+ // Calls `f` with a `Resolver` whose current lexical scope is `module`'s lexical scope,
2690+ // i.e. the module's items and the prelude (unless the module is `#[no_implicit_prelude]`).
2691+ pub fn with_module_lexical_scope < T , F > ( & mut self , module : Module < ' a > , f : F ) -> T
2692+ where F : FnOnce ( & mut Resolver < ' a > ) -> T ,
2693+ {
2694+ self . with_empty_ribs ( |this| {
2695+ this. value_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
2696+ this. type_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
2697+ f ( this)
2698+ } )
2699+ }
2700+
2701+ fn with_empty_ribs < T , F > ( & mut self , f : F ) -> T
2702+ where F : FnOnce ( & mut Resolver < ' a > ) -> T ,
2703+ {
2704+ use :: std:: mem:: replace;
2705+ let value_ribs = replace ( & mut self . value_ribs , Vec :: new ( ) ) ;
2706+ let type_ribs = replace ( & mut self . type_ribs , Vec :: new ( ) ) ;
2707+ let label_ribs = replace ( & mut self . label_ribs , Vec :: new ( ) ) ;
2708+
2709+ let result = f ( self ) ;
2710+ self . value_ribs = value_ribs;
2711+ self . type_ribs = type_ribs;
2712+ self . label_ribs = label_ribs;
2713+ result
2714+ }
2715+
26892716 fn find_fallback_in_self_type ( & mut self , name : Name ) -> FallbackSuggestion {
26902717 fn extract_node_id ( t : & Ty ) -> Option < NodeId > {
26912718 match t. node {
0 commit comments