From 6e0bd44fa3b2a7d2779fde107e033abda4155aa7 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Tue, 5 Jul 2016 08:47:58 +0000 Subject: [PATCH 1/2] Add method `with_module_lexical_scope` to `Resolver`. --- src/librustc_resolve/lib.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ed400af6685..8cfde39c82a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -980,7 +980,7 @@ pub struct Resolver<'a> { // // There will be an anonymous module created around `g` with the ID of the // entry block for `f`. - module_map: NodeMap>, + pub module_map: NodeMap>, // Whether or not to print error messages. Can be set to true // when getting additional info for error message suggestions, @@ -2686,6 +2686,33 @@ impl<'a> Resolver<'a> { rs } + // Calls `f` with a `Resolver` whose current lexical scope is `module`'s lexical scope, + // i.e. the module's items and the prelude (unless the module is `#[no_implicit_prelude]`). + pub fn with_module_lexical_scope(&mut self, module: Module<'a>, f: F) -> T + where F: FnOnce(&mut Resolver<'a>) -> T, + { + self.with_empty_ribs(|this| { + this.value_ribs.push(Rib::new(ModuleRibKind(module))); + this.type_ribs.push(Rib::new(ModuleRibKind(module))); + f(this) + }) + } + + fn with_empty_ribs(&mut self, f: F) -> T + where F: FnOnce(&mut Resolver<'a>) -> T, + { + use ::std::mem::replace; + let value_ribs = replace(&mut self.value_ribs, Vec::new()); + let type_ribs = replace(&mut self.type_ribs, Vec::new()); + let label_ribs = replace(&mut self.label_ribs, Vec::new()); + + let result = f(self); + self.value_ribs = value_ribs; + self.type_ribs = type_ribs; + self.label_ribs = label_ribs; + result + } + fn find_fallback_in_self_type(&mut self, name: Name) -> FallbackSuggestion { fn extract_node_id(t: &Ty) -> Option { match t.node { From 58dd06d9e55731ce4308d96ed680ee13286de4a2 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Tue, 5 Jul 2016 22:38:41 +0000 Subject: [PATCH 2/2] Add FIXME comment --- src/librustc_resolve/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 8cfde39c82a..c42767f95e1 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2688,6 +2688,7 @@ impl<'a> Resolver<'a> { // Calls `f` with a `Resolver` whose current lexical scope is `module`'s lexical scope, // i.e. the module's items and the prelude (unless the module is `#[no_implicit_prelude]`). + // FIXME #34673: This needs testing. pub fn with_module_lexical_scope(&mut self, module: Module<'a>, f: F) -> T where F: FnOnce(&mut Resolver<'a>) -> T, {