about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSean Bowe <ewillbefull@gmail.com>2015-09-13 21:22:30 -0600
committerSean Bowe <ewillbefull@gmail.com>2015-09-13 21:22:30 -0600
commitaf3a0b08055f9dac932264253040c3626a7052f6 (patch)
treee7b196d24ce666ca1e70661fef4b3354a822e68b
parent522d4b0a354b60b1b69d15773197c4c3dba521a5 (diff)
downloadrust-af3a0b08055f9dac932264253040c3626a7052f6.tar.gz
rust-af3a0b08055f9dac932264253040c3626a7052f6.zip
Refactor ty_infer invocation
-rw-r--r--src/librustc_typeck/astconv.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index b5b5113c487..13476ddebc1 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -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