Skip to content

Commit 9128d68

Browse files
committed
---
yaml --- r: 234236 b: refs/heads/beta c: 4fec679 h: refs/heads/master v: v3
1 parent 162310c commit 9128d68

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 3d0774f5989fc9425c5dc0ab5118fdcabba33555
26+
refs/heads/beta: 4fec679399ddaf67d15adddad2677731f94dfa36
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 370fe2786109360f7c35b8ba552b83b773dd71d6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_typeck/astconv.rs

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -408,34 +408,13 @@ fn create_substs_for_ast_path<'tcx>(
408408
.take_while(|x| x.default.is_none())
409409
.count();
410410

411-
// Fill with `ty_infer` if no params were specified, as long as
412-
// they were optional (e.g. paths inside expressions).
413-
let mut type_substs = if param_mode == PathParamMode::Optional &&
414-
types_provided.is_empty() {
415-
fn default_type_parameter<'tcx>(p: &ty::TypeParameterDef<'tcx>, self_ty: Option<Ty<'tcx>>)
416-
-> Option<ty::TypeParameterDef<'tcx>>
417-
{
418-
if let Some(ref default) = p.default {
419-
if self_ty.is_none() && default.has_self_ty() {
420-
// There is no suitable inference default for a type parameter
421-
// that references self with no self-type provided.
422-
return None;
423-
}
424-
}
425-
426-
Some(p.clone())
427-
}
428-
429-
let mut substs = region_substs.clone();
430-
431-
ty_param_defs
432-
.iter()
433-
.map(|p| this.ty_infer(default_type_parameter(p, self_ty), Some(&mut substs),
434-
Some(TypeSpace), span))
435-
.collect()
436-
} else {
437-
types_provided
438-
};
411+
let mut type_substs = get_type_substs_for_defs(this,
412+
span,
413+
types_provided,
414+
param_mode,
415+
ty_param_defs,
416+
region_substs.clone(),
417+
self_ty);
439418

440419
let supplied_ty_param_count = type_substs.len();
441420
check_type_argument_count(this.tcx(), span, supplied_ty_param_count,
@@ -499,6 +478,42 @@ fn create_substs_for_ast_path<'tcx>(
499478
substs
500479
}
501480

481+
/// Returns types_provided if it is not empty, otherwise populating the
482+
/// type parameters with inference variables as appropriate.
483+
fn get_type_substs_for_defs<'tcx>(this: &AstConv<'tcx>,
484+
span: Span,
485+
types_provided: Vec<Ty<'tcx>>,
486+
param_mode: PathParamMode,
487+
ty_param_defs: &[ty::TypeParameterDef<'tcx>],
488+
mut substs: Substs<'tcx>,
489+
self_ty: Option<Ty<'tcx>>)
490+
-> Vec<Ty<'tcx>>
491+
{
492+
fn default_type_parameter<'tcx>(p: &ty::TypeParameterDef<'tcx>, self_ty: Option<Ty<'tcx>>)
493+
-> Option<ty::TypeParameterDef<'tcx>>
494+
{
495+
if let Some(ref default) = p.default {
496+
if self_ty.is_none() && default.has_self_ty() {
497+
// There is no suitable inference default for a type parameter
498+
// that references self with no self-type provided.
499+
return None;
500+
}
501+
}
502+
503+
Some(p.clone())
504+
}
505+
506+
if param_mode == PathParamMode::Optional && types_provided.is_empty() {
507+
ty_param_defs
508+
.iter()
509+
.map(|p| this.ty_infer(default_type_parameter(p, self_ty), Some(&mut substs),
510+
Some(TypeSpace), span))
511+
.collect()
512+
} else {
513+
types_provided
514+
}
515+
}
516+
502517
struct ConvertedBinding<'tcx> {
503518
item_name: ast::Name,
504519
ty: Ty<'tcx>,

0 commit comments

Comments
 (0)