From 8797e8cabdd47d1731bbd12099d0cd5503d22d76 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 31 May 2019 16:50:44 +1000 Subject: [PATCH] Move `modern` calls inside `glob_adjust` and `reverse_glob_adjust`. --- src/librustc_resolve/lib.rs | 2 +- src/librustc_resolve/resolve_imports.rs | 8 +++----- src/libsyntax_pos/hygiene.rs | 7 ++++--- src/libsyntax_pos/lib.rs | 9 ++++----- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 99abe69017d..5f076d16bed 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4525,7 +4525,7 @@ fn get_traits_in_module_containing_item(&mut self, let mut ident = ident; if ident.span.glob_adjust( module.expansion, - binding.span.ctxt().modern(), + binding.span, ).is_none() { continue } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index c0ff7b310b5..d24d8f8c2b5 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -388,7 +388,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace) None => return Err((Undetermined, Weak::Yes)), }; let (orig_current_module, mut ident) = (self.current_module, ident.modern()); - match ident.span.glob_adjust(module.expansion, glob_import.span.ctxt().modern()) { + match ident.span.glob_adjust(module.expansion, glob_import.span) { Some(Some(def)) => self.current_module = self.macro_def_scope(def), Some(None) => {} None => continue, @@ -605,8 +605,7 @@ fn update_resolution(&mut self, module: Module<'a>, ident: Ident, ns: Name // Define `binding` in `module`s glob importers. for directive in module.glob_importers.borrow_mut().iter() { let mut ident = ident.modern(); - let scope = match ident.span.reverse_glob_adjust(module.expansion, - directive.span.ctxt().modern()) { + let scope = match ident.span.reverse_glob_adjust(module.expansion, directive.span) { Some(Some(def)) => self.macro_def_scope(def), Some(None) => directive.parent_scope.module, None => continue, @@ -1359,8 +1358,7 @@ fn resolve_glob_import(&mut self, directive: &'b ImportDirective<'b>) { resolution.borrow().binding().map(|binding| (ident, binding)) }).collect::>(); for ((mut ident, ns), binding) in bindings { - let scope = match ident.span.reverse_glob_adjust(module.expansion, - directive.span.ctxt().modern()) { + let scope = match ident.span.reverse_glob_adjust(module.expansion, directive.span) { Some(Some(def)) => self.macro_def_scope(def), Some(None) => self.current_module, None => continue, diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 445d4271d89..39a7124c756 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -463,9 +463,9 @@ pub fn adjust(&mut self, expansion: Mark) -> Option { /// ``` /// This returns `None` if the context cannot be glob-adjusted. /// Otherwise, it returns the scope to use when privacy checking (see `adjust` for details). - pub fn glob_adjust(&mut self, expansion: Mark, mut glob_ctxt: SyntaxContext) - -> Option> { + pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option> { let mut scope = None; + let mut glob_ctxt = glob_span.ctxt().modern(); while !expansion.outer_is_descendant_of(glob_ctxt) { scope = Some(glob_ctxt.remove_mark()); if self.remove_mark() != scope.unwrap() { @@ -485,12 +485,13 @@ pub fn glob_adjust(&mut self, expansion: Mark, mut glob_ctxt: SyntaxContext) /// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope)); /// } /// ``` - pub fn reverse_glob_adjust(&mut self, expansion: Mark, mut glob_ctxt: SyntaxContext) + pub fn reverse_glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option> { if self.adjust(expansion).is_some() { return None; } + let mut glob_ctxt = glob_span.ctxt().modern(); let mut marks = Vec::new(); while !expansion.outer_is_descendant_of(glob_ctxt) { marks.push(glob_ctxt.remove_mark()); diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 30e075a3396..9bab95efd1b 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -535,19 +535,18 @@ pub fn adjust(&mut self, expansion: Mark) -> Option { } #[inline] - pub fn glob_adjust(&mut self, expansion: Mark, glob_ctxt: SyntaxContext) - -> Option> { + pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option> { let mut span = self.data(); - let mark = span.ctxt.glob_adjust(expansion, glob_ctxt); + let mark = span.ctxt.glob_adjust(expansion, glob_span); *self = Span::new(span.lo, span.hi, span.ctxt); mark } #[inline] - pub fn reverse_glob_adjust(&mut self, expansion: Mark, glob_ctxt: SyntaxContext) + pub fn reverse_glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option> { let mut span = self.data(); - let mark = span.ctxt.reverse_glob_adjust(expansion, glob_ctxt); + let mark = span.ctxt.reverse_glob_adjust(expansion, glob_span); *self = Span::new(span.lo, span.hi, span.ctxt); mark } -- 2.44.0