From af3a0b08055f9dac932264253040c3626a7052f6 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sun, 13 Sep 2015 21:22:30 -0600 Subject: [PATCH] Refactor ty_infer invocation --- src/librustc_typeck/astconv.rs | 27 ++++++++++++++++----------- 1 file 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>) + -> Option> + { + 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 -- GitLab