Account for blocks in arguments
When giving an error about an obligation introduced by a function call that an argument doesn't fulfill, and that argument is a block, add a span_label pointing at the innermost tail expression.
This commit is contained in:
parent
569a842730
commit
22318f1a31
1 changed files with 22 additions and 2 deletions
|
@ -2296,11 +2296,31 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ObligationCauseCode::FunctionArgumentObligation {
|
ObligationCauseCode::FunctionArgumentObligation {
|
||||||
arg_hir_id: _,
|
arg_hir_id,
|
||||||
call_hir_id,
|
call_hir_id,
|
||||||
ref parent_code,
|
ref parent_code,
|
||||||
} => {
|
} => {
|
||||||
let hir = self.tcx.hir();
|
let hir = self.tcx.hir();
|
||||||
|
if let Some(Node::Expr(expr @ hir::Expr { kind: hir::ExprKind::Block(..), .. })) =
|
||||||
|
hir.find(arg_hir_id)
|
||||||
|
{
|
||||||
|
let in_progress_typeck_results =
|
||||||
|
self.in_progress_typeck_results.map(|t| t.borrow());
|
||||||
|
let parent_id = hir.local_def_id(hir.get_parent_item(arg_hir_id));
|
||||||
|
let typeck_results: &TypeckResults<'tcx> = match &in_progress_typeck_results {
|
||||||
|
Some(t) if t.hir_owner == parent_id => t,
|
||||||
|
_ => self.tcx.typeck(parent_id),
|
||||||
|
};
|
||||||
|
let ty = typeck_results.expr_ty_adjusted(expr);
|
||||||
|
err.span_label(
|
||||||
|
expr.peel_blocks().span,
|
||||||
|
&if ty.references_error() {
|
||||||
|
String::new()
|
||||||
|
} else {
|
||||||
|
format!("this tail expression is of type `{:?}`", ty)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
if let Some(Node::Expr(hir::Expr {
|
if let Some(Node::Expr(hir::Expr {
|
||||||
kind:
|
kind:
|
||||||
hir::ExprKind::Call(hir::Expr { span, .. }, _)
|
hir::ExprKind::Call(hir::Expr { span, .. }, _)
|
||||||
|
@ -2308,7 +2328,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
..
|
..
|
||||||
})) = hir.find(call_hir_id)
|
})) = hir.find(call_hir_id)
|
||||||
{
|
{
|
||||||
err.span_label(*span, "required by a bound in this call");
|
err.span_label(*span, "required by a bound introduced by this call");
|
||||||
}
|
}
|
||||||
ensure_sufficient_stack(|| {
|
ensure_sufficient_stack(|| {
|
||||||
self.note_obligation_cause_code(
|
self.note_obligation_cause_code(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue