]> git.lizzy.rs Git - rust.git/commitdiff
Refactor ty_infer invocation
authorSean Bowe <ewillbefull@gmail.com>
Mon, 14 Sep 2015 03:22:30 +0000 (21:22 -0600)
committerSean Bowe <ewillbefull@gmail.com>
Mon, 14 Sep 2015 03:22:30 +0000 (21:22 -0600)
src/librustc_typeck/astconv.rs

index b5b5113c4870d5134c204c2d61f990eb5e9a060e..13476ddebc17f7a32d64364cb5541f5180a45bb2 100644 (file)
@@ -412,21 +412,26 @@ fn create_substs_for_ast_path<'tcx>(
     // they were optional (e.g. paths inside expressions).
     let mut type_substs = if param_mode == PathParamMode::Optional &&
                              types_provided.is_empty() {
+        fn default_type_parameter<'tcx>(p: &ty::TypeParameterDef<'tcx>, self_ty: Option<Ty<'tcx>>)
+                                        -> Option<ty::TypeParameterDef<'tcx>>
+        {
+            if let Some(ref default) = p.default {
+                if self_ty.is_none() && default.has_self_ty() {
+                    // There is no suitable inference default for a type parameter
+                    // that references self with no self-type provided.
+                    return None;
+                }
+            }
+
+            Some(p.clone())
+        }
+
         let mut substs = region_substs.clone();
 
         ty_param_defs
             .iter()
-            .map(|p| {
-                if let Some(ref default) = p.default {
-                    if self_ty.is_none() && default.has_self_ty() {
-                        // There is no suitable inference default for a type parameter
-                        // that references Self with no self-type provided.
-                        return this.ty_infer(None, Some(&mut substs), Some(TypeSpace), span);
-                    }
-                }
-
-                this.ty_infer(Some(p.clone()), Some(&mut substs), Some(TypeSpace), span)
-            })
+            .map(|p| this.ty_infer(default_type_parameter(p, self_ty), Some(&mut substs),
+                                   Some(TypeSpace), span))
             .collect()
     } else {
         types_provided