Skip to content

Commit

Permalink
Account for blocks in arguments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
estebank committed Sep 16, 2021
1 parent 569a842 commit 22318f1
Showing 1 changed file with 22 additions and 2 deletions.
Expand Up @@ -2296,19 +2296,39 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
});
}
ObligationCauseCode::FunctionArgumentObligation {
arg_hir_id: _,
arg_hir_id,
call_hir_id,
ref parent_code,
} => {
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 {
kind:
hir::ExprKind::Call(hir::Expr { span, .. }, _)
| hir::ExprKind::MethodCall(_, span, ..),
..
})) = 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(|| {
self.note_obligation_cause_code(
Expand Down

0 comments on commit 22318f1

Please sign in to comment.