From 74496bc4d9f64ea01ae3714b9680cc22c1535cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 10 Aug 2025 19:26:03 +0000 Subject: [PATCH] review comments --- .../rustc_borrowck/src/diagnostics/move_errors.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 5adbaca7e113..af71db694832 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -571,9 +571,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { fn get_closure_bound_clause_span(&self, def_id: DefId) -> Span { let tcx = self.infcx.tcx; let typeck_result = tcx.typeck(self.mir_def_id()); - let Some(closure_def_id) = def_id.as_local() else { return DUMMY_SP }; - let hir::Node::Expr(expr) = tcx.hir_node_by_def_id(closure_def_id) else { return DUMMY_SP }; - let hir::Node::Expr(parent) = tcx.parent_hir_node(expr.hir_id) else { return DUMMY_SP }; + // Check whether the closure is an argument to a call, if so, + // get the instantiated where-bounds of that call. + let closure_hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local()); + let hir::Node::Expr(parent) = tcx.parent_hir_node(closure_hir_id) else { return DUMMY_SP }; + let predicates = match parent.kind { hir::ExprKind::Call(callee, _) => { let Some(ty) = typeck_result.node_type_opt(callee.hir_id) else { return DUMMY_SP }; @@ -589,9 +591,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } _ => return DUMMY_SP, }; + + // Check whether one of the where-bounds requires the closure to impl `Fn[Mut]`. for (pred, span) in predicates.predicates.iter().zip(predicates.spans.iter()) { - tracing::info!(?pred); - tracing::info!(?span); if let Some(clause) = pred.as_trait_clause() && let ty::Closure(clause_closure_def_id, _) = clause.self_ty().skip_binder().kind() && *clause_closure_def_id == def_id