about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Kuber <esteban@kuber.com.ar>2021-09-07 11:57:01 +0000
committerEsteban Kuber <esteban@kuber.com.ar>2021-09-16 12:12:28 +0000
commit22318f1a31d8ef4d46036b552fd848314d603978 (patch)
treee31a5bffaa94aa6ba89c613adaca767dd4daa325
parent569a842730851ea8521f20f48fa96fd9f3e5db95 (diff)
downloadrust-22318f1a31d8ef4d46036b552fd848314d603978.tar.gz
rust-22318f1a31d8ef4d46036b552fd848314d603978.zip
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.
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index 9e8d6fb6225..92cf4fb414a 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -2296,11 +2296,31 @@ 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, .. }, _)
@@ -2308,7 +2328,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                     ..
                 })) = 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(