]> git.lizzy.rs Git - rust.git/commitdiff
Add `modernize_and_adjust` methods.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 3 Jun 2019 06:10:03 +0000 (16:10 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Tue, 4 Jun 2019 23:09:35 +0000 (09:09 +1000)
These combine two `HygieneData::with` calls into one.

src/librustc/ty/mod.rs
src/librustc_resolve/lib.rs
src/libsyntax_pos/hygiene.rs
src/libsyntax_pos/lib.rs

index 408f2d9f2493c33f8506b1e8aac2ee005fba563d..e585f9939a0141e0f48e6bc717b779f95ee18ebe 100644 (file)
@@ -3101,15 +3101,13 @@ fn expansion_that_defined(self, scope: DefId) -> Mark {
     }
 
     pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
-        ident = ident.modern();
-        ident.span.adjust(self.expansion_that_defined(scope));
+        ident.span.modernize_and_adjust(self.expansion_that_defined(scope));
         ident
     }
 
     pub fn adjust_ident_and_get_scope(self, mut ident: Ident, scope: DefId, block: hir::HirId)
                                       -> (Ident, DefId) {
-        ident = ident.modern();
-        let scope = match ident.span.adjust(self.expansion_that_defined(scope)) {
+        let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) {
             Some(actual_expansion) =>
                 self.hir().definitions().parent_module_of_macro_def(actual_expansion),
             None => self.hir().get_module_parent_by_hir_id(block),
index 5f076d16bed5e84a2fa5569a6c594e7af0b31d3e..9b9cf80f822b027c8487f31c4b7b0693c1eb3d73 100644 (file)
@@ -2330,14 +2330,12 @@ fn resolve_ident_in_module_ext(
         let orig_current_module = self.current_module;
         match module {
             ModuleOrUniformRoot::Module(module) => {
-                ident.span = ident.span.modern();
-                if let Some(def) = ident.span.adjust(module.expansion) {
+                if let Some(def) = ident.span.modernize_and_adjust(module.expansion) {
                     self.current_module = self.macro_def_scope(def);
                 }
             }
             ModuleOrUniformRoot::ExternPrelude => {
-                ident.span = ident.span.modern();
-                ident.span.adjust(Mark::root());
+                ident.span.modernize_and_adjust(Mark::root());
             }
             ModuleOrUniformRoot::CrateRootAndExternPrelude |
             ModuleOrUniformRoot::CurrentScope => {
index 62a2d93a52e41875a7acf6b0ba1df798c9811c4c..213993996a63cc3fd3ee15808e85cdc5dc7346a8 100644 (file)
@@ -508,6 +508,14 @@ pub fn adjust(&mut self, expansion: Mark) -> Option<Mark> {
         HygieneData::with(|data| data.adjust(self, expansion))
     }
 
+    /// Like `SyntaxContext::adjust`, but also modernizes `self`.
+    pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
+        HygieneData::with(|data| {
+            *self = data.modern(*self);
+            data.adjust(self, expansion)
+        })
+    }
+
     /// Adjust this context for resolution in a scope created by the given expansion
     /// via a glob import with the given `SyntaxContext`.
     /// For example:
index 9bab95efd1bb7dc1e72757211a595e91002597c4..24aa82184ced58d9e4c7900a9c444b35ccd8545c 100644 (file)
@@ -534,6 +534,14 @@ pub fn adjust(&mut self, expansion: Mark) -> Option<Mark> {
         mark
     }
 
+    #[inline]
+    pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
+        let mut span = self.data();
+        let mark = span.ctxt.modernize_and_adjust(expansion);
+        *self = Span::new(span.lo, span.hi, span.ctxt);
+        mark
+    }
+
     #[inline]
     pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option<Option<Mark>> {
         let mut span = self.data();