about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2022-07-26 14:49:24 -0300
committerSantiago Pastorino <spastorino@gmail.com>2022-08-04 11:26:52 -0300
commit25825cd4fa735c4b6d8b004940709bc066477c7c (patch)
treea2a149a7ad2165ffa37bde49c429c3fd91c9c418
parentfac763168f35bc24b83c435d4d7009dca648432b (diff)
downloadrust-25825cd4fa735c4b6d8b004940709bc066477c7c.tar.gz
rust-25825cd4fa735c4b6d8b004940709bc066477c7c.zip
Extract create_and_capture_lifetime_defs function
-rw-r--r--compiler/rustc_ast_lowering/src/lib.rs155
1 files changed, 81 insertions, 74 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index aa84373b6cf..9009ae7a051 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -1392,80 +1392,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                 debug!(?lifetimes_in_bounds);
                 debug!(?binders_to_ignore);
 
-                for lifetime in &lifetimes_in_bounds {
-                    let ident = lifetime.ident;
-                    let span = ident.span;
-
-                    let res =
-                        lctx.resolver.get_lifetime_res(lifetime.id).unwrap_or(LifetimeRes::Error);
-                    debug!(?res);
-
-                    if let Some(mut captured_lifetimes) = lctx.captured_lifetimes.take() {
-                        match res {
-                            LifetimeRes::Param { param, binder } => {
-                                if !captured_lifetimes.binders_to_ignore.contains(&binder)
-                                    && !binders_to_ignore
-                                        .get(&lifetime.id)
-                                        .unwrap_or(&Vec::new())
-                                        .contains(&binder)
-                                {
-                                    match captured_lifetimes.captures.entry(param) {
-                                        Entry::Occupied(_) => {}
-                                        Entry::Vacant(v) => {
-                                            let node_id = lctx.next_node_id();
-                                            let name = ParamName::Plain(ident);
-
-                                            lctx.create_def(
-                                                captured_lifetimes.parent_def_id,
-                                                node_id,
-                                                DefPathData::LifetimeNs(name.ident().name),
-                                            );
-
-                                            v.insert((span, node_id, name, res));
-                                        }
-                                    }
-                                }
-                            }
-
-                            LifetimeRes::Fresh { param, binder } => {
-                                debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
-                                if !captured_lifetimes.binders_to_ignore.contains(&binder)
-                                    && !binders_to_ignore
-                                        .get(&lifetime.id)
-                                        .unwrap_or(&Vec::new())
-                                        .contains(&binder)
-                                {
-                                    let param = lctx.local_def_id(param);
-                                    match captured_lifetimes.captures.entry(param) {
-                                        Entry::Occupied(_) => {}
-                                        Entry::Vacant(v) => {
-                                            let node_id = lctx.next_node_id();
-
-                                            let name = ParamName::Fresh;
-
-                                            lctx.create_def(
-                                                captured_lifetimes.parent_def_id,
-                                                node_id,
-                                                DefPathData::LifetimeNs(kw::UnderscoreLifetime),
-                                            );
-
-                                            v.insert((span, node_id, name, res));
-                                        }
-                                    }
-                                }
-                            }
-
-                            LifetimeRes::Infer | LifetimeRes::Static | LifetimeRes::Error => {}
-
-                            res => panic!(
-                                "Unexpected lifetime resolution {:?} for {:?} at {:?}",
-                                res, lifetime.ident, lifetime.ident.span
-                            ),
-                        }
-
-                        lctx.captured_lifetimes = Some(captured_lifetimes);
-                    }
-                }
+                lctx.create_and_capture_lifetime_defs(&lifetimes_in_bounds, &binders_to_ignore);
 
                 let ret = lctx.lower_param_bounds(bounds, itctx, false);
 
@@ -1554,6 +1481,86 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         hir::OwnerNode::Item(self.arena.alloc(opaque_ty_item))
     }
 
+    fn create_and_capture_lifetime_defs(
+        &mut self,
+        lifetimes_in_bounds: &[&Lifetime],
+        binders_to_ignore: &FxHashMap<NodeId, Vec<NodeId>>,
+    ) {
+        for lifetime in lifetimes_in_bounds {
+            let ident = lifetime.ident;
+            let span = ident.span;
+
+            let res = self.resolver.get_lifetime_res(lifetime.id).unwrap_or(LifetimeRes::Error);
+            debug!(?res);
+
+            if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
+                match res {
+                    LifetimeRes::Param { param, binder } => {
+                        if !captured_lifetimes.binders_to_ignore.contains(&binder)
+                            && !binders_to_ignore
+                                .get(&lifetime.id)
+                                .unwrap_or(&Vec::new())
+                                .contains(&binder)
+                        {
+                            match captured_lifetimes.captures.entry(param) {
+                                Entry::Occupied(_) => {}
+                                Entry::Vacant(v) => {
+                                    let node_id = self.next_node_id();
+                                    let name = ParamName::Plain(ident);
+
+                                    self.create_def(
+                                        captured_lifetimes.parent_def_id,
+                                        node_id,
+                                        DefPathData::LifetimeNs(name.ident().name),
+                                    );
+
+                                    v.insert((span, node_id, name, res));
+                                }
+                            }
+                        }
+                    }
+
+                    LifetimeRes::Fresh { param, binder } => {
+                        debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
+                        if !captured_lifetimes.binders_to_ignore.contains(&binder)
+                            && !binders_to_ignore
+                                .get(&lifetime.id)
+                                .unwrap_or(&Vec::new())
+                                .contains(&binder)
+                        {
+                            let param = self.local_def_id(param);
+                            match captured_lifetimes.captures.entry(param) {
+                                Entry::Occupied(_) => {}
+                                Entry::Vacant(v) => {
+                                    let node_id = self.next_node_id();
+
+                                    let name = ParamName::Fresh;
+
+                                    self.create_def(
+                                        captured_lifetimes.parent_def_id,
+                                        node_id,
+                                        DefPathData::LifetimeNs(kw::UnderscoreLifetime),
+                                    );
+
+                                    v.insert((span, node_id, name, res));
+                                }
+                            }
+                        }
+                    }
+
+                    LifetimeRes::Infer | LifetimeRes::Static | LifetimeRes::Error => {}
+
+                    res => panic!(
+                        "Unexpected lifetime resolution {:?} for {:?} at {:?}",
+                        res, lifetime.ident, lifetime.ident.span
+                    ),
+                }
+
+                self.captured_lifetimes = Some(captured_lifetimes);
+            }
+        }
+    }
+
     fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
         // Skip the `...` (`CVarArgs`) trailing arguments from the AST,
         // as they are not explicit in HIR/Ty function signatures.