Skip to content

Commit bbdca2c

Browse files
jroeschJared Roesch
authored andcommitted
Correctly collect defaults from type alises in astconv
1 parent 91de8e6 commit bbdca2c

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
@@ -111,7 +111,7 @@ pub trait AstConv<'tcx> {
111111
}
112112

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

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

@@ -1677,7 +1677,7 @@ pub fn ty_of_arg<'tcx>(this: &AstConv<'tcx>,
16771677
{
16781678
match a.ty.node {
16791679
ast::TyInfer if expected_ty.is_some() => expected_ty.unwrap(),
1680-
ast::TyInfer => this.ty_infer(a.ty.span),
1680+
ast::TyInfer => this.ty_infer(None, a.ty.span),
16811681
_ => ast_ty_to_ty(this, rscope, &*a.ty),
16821682
}
16831683
}
@@ -1796,7 +1796,7 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
17961796

17971797
let output_ty = match decl.output {
17981798
ast::Return(ref output) if output.node == ast::TyInfer =>
1799-
ty::FnConverging(this.ty_infer(output.span)),
1799+
ty::FnConverging(this.ty_infer(None, output.span)),
18001800
ast::Return(ref output) =>
18011801
ty::FnConverging(convert_ty_with_lifetime_elision(this,
18021802
implied_output_region,
@@ -1936,7 +1936,7 @@ pub fn ty_of_closure<'tcx>(
19361936
_ if is_infer && expected_ret_ty.is_some() =>
19371937
expected_ret_ty.unwrap(),
19381938
_ if is_infer =>
1939-
ty::FnConverging(this.ty_infer(decl.output.span())),
1939+
ty::FnConverging(this.ty_infer(None, decl.output.span())),
19401940
ast::Return(ref output) =>
19411941
ty::FnConverging(ast_ty_to_ty(this, &rb, &**output)),
19421942
ast::DefaultReturn(..) => unreachable!(),

src/librustc_typeck/check/mod.rs

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

1141-
fn ty_infer(&self, _span: Span) -> Ty<'tcx> {
1142-
self.infcx().next_ty_var()
1141+
fn ty_infer(&self, default: Option<Ty<'tcx>>, _span: Span) -> Ty<'tcx> {
1142+
let ty_var = self.infcx().next_ty_var();
1143+
match default {
1144+
Some(default) => { self.infcx().defaults.borrow_mut().insert(ty_var, default); }
1145+
None => {}
1146+
}
1147+
ty_var
11431148
}
11441149

11451150
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)