]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_resolve/lib.rs
rustc: replace Res in hir::Upvar with only Local/Upvar data.
[rust.git] / src / librustc_resolve / lib.rs
index 9b7b44025c13f73043590e2edca2d2dddbeea68a..67ed6a773056bd7cb0a4f42312dc5ff1df611df1 100644 (file)
@@ -762,7 +762,7 @@ fn visit_mod(
                 ItemKind::Use(..) => {
                     // don't suggest placing a use before the prelude
                     // import or other generated ones
-                    if item.span.ctxt().outer().expn_info().is_none() {
+                    if item.span.ctxt().outer_expn_info().is_none() {
                         self.span = Some(item.span.shrink_to_lo());
                         self.found_use = true;
                         return;
@@ -772,7 +772,7 @@ fn visit_mod(
                 ItemKind::ExternCrate(_) => {}
                 // but place them before the first other item
                 _ => if self.span.map_or(true, |span| item.span < span ) {
-                    if item.span.ctxt().outer().expn_info().is_none() {
+                    if item.span.ctxt().outer_expn_info().is_none() {
                         // don't insert between attributes and an item
                         if item.attrs.is_empty() {
                             self.span = Some(item.span.shrink_to_lo());
@@ -2308,7 +2308,7 @@ fn resolve_ident_in_lexical_scope(&mut self,
 
     fn hygienic_lexical_parent(&mut self, module: Module<'a>, span: &mut Span)
                                -> Option<Module<'a>> {
-        if !module.expansion.is_descendant_of(span.ctxt().outer()) {
+        if !module.expansion.outer_is_descendant_of(span.ctxt()) {
             return Some(self.macro_def_scope(span.remove_mark()));
         }
 
@@ -2344,7 +2344,7 @@ fn hygienic_lexical_parent_with_compatibility_fallback(&mut self, module: Module
             module.expansion.is_descendant_of(parent.expansion) {
                 // The macro is a proc macro derive
                 if module.expansion.looks_like_proc_macro_derive() {
-                    if parent.expansion.is_descendant_of(span.ctxt().outer()) {
+                    if parent.expansion.outer_is_descendant_of(span.ctxt()) {
                         *poisoned = Some(node_id);
                         return module.parent;
                     }
@@ -4040,7 +4040,7 @@ fn adjust_local_res(&mut self,
             Res::Upvar(..) => {
                 span_bug!(span, "unexpected {:?} in bindings", res)
             }
-            Res::Local(node_id) => {
+            Res::Local(var_id) => {
                 use ResolutionError::*;
                 let mut res_err = None;
 
@@ -4051,27 +4051,31 @@ fn adjust_local_res(&mut self,
                             // Nothing to do. Continue.
                         }
                         ClosureRibKind(function_id) => {
-                            let prev_res = res;
+                            let parent = match res {
+                                Res::Upvar(_, i, closure) => Some((closure, i)),
+                                _ => None,
+                            };
 
                             let seen = self.upvars_seen
                                            .entry(function_id)
                                            .or_default();
-                            if let Some(&index) = seen.get(&node_id) {
-                                res = Res::Upvar(node_id, index, function_id);
+                            if let Some(&index) = seen.get(&var_id) {
+                                res = Res::Upvar(var_id, index, function_id);
                                 continue;
                             }
                             let vec = self.upvars
                                           .entry(function_id)
                                           .or_default();
                             let depth = vec.len();
-                            res = Res::Upvar(node_id, depth, function_id);
+                            res = Res::Upvar(var_id, depth, function_id);
 
                             if record_used {
                                 vec.push(Upvar {
-                                    res: prev_res,
+                                    var_id,
+                                    parent,
                                     span,
                                 });
-                                seen.insert(node_id, depth);
+                                seen.insert(var_id, depth);
                             }
                         }
                         ItemRibKind | FnItemRibKind | AssocItemRibKind => {