Skip to content

Commit 2bec590

Browse files
committed
Correctly collect defaults from type alises in astconv
1 parent 6388a44 commit 2bec590

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub trait AstConv<'tcx> {
109109
}
110110

111111
/// What type should we use when a type is omitted?
112-
fn ty_infer(&self, span: Span) -> Ty<'tcx>;
112+
fn ty_infer(&self, default: Option<Ty<'tcx>>, span: Span) -> Ty<'tcx>;
113113

114114
/// Projecting an associated type from a (potentially)
115115
/// higher-ranked trait reference is more complicated, because of
@@ -401,7 +401,7 @@ fn create_substs_for_ast_path<'tcx>(
401401
// they were optional (e.g. paths inside expressions).
402402
let mut type_substs = if param_mode == PathParamMode::Optional &&
403403
types_provided.is_empty() {
404-
(0..formal_ty_param_count).map(|_| this.ty_infer(span)).collect()
404+
ty_param_defs.iter().map(|p| this.ty_infer(p.default, span)).collect()
405405
} else {
406406
types_provided
407407
};
@@ -1665,7 +1665,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
16651665
// values in a ExprClosure, or as
16661666
// the type of local variables. Both of these cases are
16671667
// handled specially and will not descend into this routine.
1668-
this.ty_infer(ast_ty.span)
1668+
this.ty_infer(None, ast_ty.span)
16691669
}
16701670
};
16711671

@@ -1681,7 +1681,7 @@ pub fn ty_of_arg<'tcx>(this: &AstConv<'tcx>,
16811681
{
16821682
match a.ty.node {
16831683
ast::TyInfer if expected_ty.is_some() => expected_ty.unwrap(),
1684-
ast::TyInfer => this.ty_infer(a.ty.span),
1684+
ast::TyInfer => this.ty_infer(None, a.ty.span),
16851685
_ => ast_ty_to_ty(this, rscope, &*a.ty),
16861686
}
16871687
}
@@ -1800,7 +1800,7 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
18001800

18011801
let output_ty = match decl.output {
18021802
ast::Return(ref output) if output.node == ast::TyInfer =>
1803-
ty::FnConverging(this.ty_infer(output.span)),
1803+
ty::FnConverging(this.ty_infer(None, output.span)),
18041804
ast::Return(ref output) =>
18051805
ty::FnConverging(convert_ty_with_lifetime_elision(this,
18061806
implied_output_region,
@@ -1940,7 +1940,7 @@ pub fn ty_of_closure<'tcx>(
19401940
_ if is_infer && expected_ret_ty.is_some() =>
19411941
expected_ret_ty.unwrap(),
19421942
_ if is_infer =>
1943-
ty::FnConverging(this.ty_infer(decl.output.span())),
1943+
ty::FnConverging(this.ty_infer(None, decl.output.span())),
19441944
ast::Return(ref output) =>
19451945
ty::FnConverging(ast_ty_to_ty(this, &rb, &**output)),
19461946
ast::DefaultReturn(..) => unreachable!(),

src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,13 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
11321132
trait_def.associated_type_names.contains(&assoc_name)
11331133
}
11341134

1135-
fn ty_infer(&self, _span: Span) -> Ty<'tcx> {
1136-
self.infcx().next_ty_var()
1135+
fn ty_infer(&self, default: Option<Ty<'tcx>>, _span: Span) -> Ty<'tcx> {
1136+
let ty_var = self.infcx().next_ty_var();
1137+
match default {
1138+
Some(default) => { self.infcx().defaults.borrow_mut().insert(ty_var, default); }
1139+
None => {}
1140+
}
1141+
ty_var
11371142
}
11381143

11391144
fn projected_ty_from_poly_trait_ref(&self,

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<'a, 'tcx> AstConv<'tcx> for ItemCtxt<'a, 'tcx> {
404404
}
405405
}
406406

407-
fn ty_infer(&self, span: Span) -> Ty<'tcx> {
407+
fn ty_infer(&self, _default: Option<Ty<'tcx>>, span: Span) -> Ty<'tcx> {
408408
span_err!(self.tcx().sess, span, E0121,
409409
"the type placeholder `_` is not allowed within types on item signatures");
410410
self.tcx().types.err

0 commit comments

Comments
 (0)