Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new rules for merging expected and supplied types in closure signatures #45072

Merged
merged 4 commits into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
.filter(|&&r| !skol_resolution_map.contains_key(r))
.cloned()
.next()
.expect("no representative region");
.unwrap_or_else(|| {
bug!("no representative region for `{:?}` in `{:?}`",
skol, regions)
});

(skol, representative)
})
Expand Down
54 changes: 0 additions & 54 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,60 +1206,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
bare_fn_ty
}

pub fn ty_of_closure(&self,
unsafety: hir::Unsafety,
decl: &hir::FnDecl,
abi: abi::Abi,
expected_sig: Option<ty::FnSig<'tcx>>)
-> ty::PolyFnSig<'tcx>
{
debug!("ty_of_closure(expected_sig={:?})",
expected_sig);

let input_tys = decl.inputs.iter().enumerate().map(|(i, a)| {
let expected_arg_ty = expected_sig.as_ref().and_then(|e| {
// no guarantee that the correct number of expected args
// were supplied
if i < e.inputs().len() {
Some(e.inputs()[i])
} else {
None
}
});
self.ty_of_arg(a, expected_arg_ty)
});

let expected_ret_ty = expected_sig.as_ref().map(|e| e.output());

let output_ty = match decl.output {
hir::Return(ref output) => {
if let (&hir::TyInfer, Some(expected_ret_ty)) = (&output.node, expected_ret_ty) {
self.record_ty(output.hir_id, expected_ret_ty, output.span);
expected_ret_ty
} else {
self.ast_ty_to_ty(&output)
}
}
hir::DefaultReturn(span) => {
if let Some(expected_ret_ty) = expected_ret_ty {
expected_ret_ty
} else {
self.ty_infer(span)
}
}
};

debug!("ty_of_closure: output_ty={:?}", output_ty);

ty::Binder(self.tcx().mk_fn_sig(
input_tys,
output_ty,
decl.variadic,
unsafety,
abi
))
}

/// Given the bounds on an object, determines what single region bound (if any) we can
/// use to summarize this type. The basic idea is that we will use the bound the user
/// provided, if they provided one, and otherwise search the supertypes of trait bounds
Expand Down
Loading