]> git.lizzy.rs Git - rust.git/commitdiff
resolve: extract `resolve_params`.
authorMazdak Farrokhzad <twingoow@gmail.com>
Wed, 28 Aug 2019 05:20:54 +0000 (07:20 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Thu, 5 Sep 2019 06:33:09 +0000 (08:33 +0200)
src/librustc_resolve/late.rs

index e15d02a9f7ec7abcd69bc082aaf9a6ecd9b64a0b..4595b1ff3f1cbdcb5410cc335c1e692139e9dbac 100644 (file)
@@ -425,14 +425,8 @@ fn visit_fn(&mut self,
         self.label_ribs.push(Rib::new(rib_kind));
 
         // Add each argument to the rib.
-        let mut bindings_list = FxHashMap::default();
-        for argument in &declaration.inputs {
-            self.resolve_pattern(&argument.pat, PatternSource::FnParam, &mut bindings_list);
-
-            self.visit_ty(&argument.ty);
+        self.resolve_params(&declaration.inputs);
 
-            debug!("(resolving function) recorded argument");
-        }
         visit::walk_fn_ret_ty(self, &declaration.output);
 
         // Resolve the function body, potentially inside the body of an async closure
@@ -1135,6 +1129,15 @@ fn check_trait_item<F>(&mut self, ident: Ident, ns: Namespace, span: Span, err:
         }
     }
 
+    fn resolve_params(&mut self, params: &[Arg]) {
+        let mut bindings_list = FxHashMap::default();
+        for param in params {
+            self.resolve_pattern(&param.pat, PatternSource::FnParam, &mut bindings_list);
+            self.visit_ty(&param.ty);
+            debug!("(resolving function / closure) recorded parameter");
+        }
+    }
+
     fn resolve_local(&mut self, local: &Local) {
         // Resolve the type.
         walk_list!(self, visit_ty, &local.ty);
@@ -1860,20 +1863,12 @@ fn resolve_expr(&mut self, expr: &Expr, parent: Option<&Expr>) {
             // `async |x| ...` gets desugared to `|x| future_from_generator(|| ...)`, so we need to
             // resolve the arguments within the proper scopes so that usages of them inside the
             // closure are detected as upvars rather than normal closure arg usages.
-            ExprKind::Closure(
-                _, IsAsync::Async { .. }, _,
-                ref fn_decl, ref body, _span,
-            ) => {
-                let rib_kind = NormalRibKind;
-                self.ribs[ValueNS].push(Rib::new(rib_kind));
+            ExprKind::Closure(_, IsAsync::Async { .. }, _, ref fn_decl, ref body, _span) => {
+                self.ribs[ValueNS].push(Rib::new(NormalRibKind));
                 // Resolve arguments:
-                let mut bindings_list = FxHashMap::default();
-                for argument in &fn_decl.inputs {
-                    self.resolve_pattern(&argument.pat, PatternSource::FnParam, &mut bindings_list);
-                    self.visit_ty(&argument.ty);
-                }
-                // No need to resolve return type-- the outer closure return type is
-                // FunctionRetTy::Default
+                self.resolve_params(&fn_decl.inputs);
+                // No need to resolve return type --
+                // the outer closure return type is `FunctionRetTy::Default`.
 
                 // Now resolve the inner closure
                 {