about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-12-07 11:11:06 -0800
committerEsteban Küber <esteban@kuber.com.ar>2022-12-11 09:46:02 -0800
commit71db025cfa85ea3c1e7d628f4c596ca498c7acf0 (patch)
tree17572e8ecd0cd5aa7394ecd315d950f20f92d103 /compiler/rustc_trait_selection
parent64bc975d27f86aaa1d3d94921c9c042477b4e88b (diff)
Account for method call chains split across multiple bindings
Diffstat (limited to 'compiler/rustc_trait_selection')
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs12
1 files changed, 12 insertions, 0 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 2f9b8c21071..87ab863fa7b 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -2977,6 +2977,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
                             prev_ty = self.resolve_vars_if_possible(
                                 typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(tcx.ty_error()),
                             );
+
+                            if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
+                                && let hir::Path { res: hir::def::Res::Local(hir_id), .. } = path
+                                && let Some(hir::Node::Pat(binding)) = self.tcx.hir().find(*hir_id)
+                                && let parent_hir_id = self.tcx.hir().get_parent_node(binding.hir_id)
+                                && let Some(hir::Node::Local(local)) = self.tcx.hir().find(parent_hir_id)
+                                && let Some(binding_expr) = local.init
+                            {
+                                // We've reached the root of the method call chain and it is a
+                                // binding. Get the binding creation and try to continue the chain.
+                                expr = binding_expr;
+                            }
                         }
 
                         // We want the type before deref coercions, otherwise we talk about `&[_]`