about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-07-25 11:16:32 +0200
committerGitHub <noreply@github.com>2025-07-25 11:16:32 +0200
commit2e54f7f0a191a9319bf95f18810d48bd6c200e7e (patch)
treed121ba910f3cb68bf531243e101a8be38ba376c9 /compiler
parentb56aaec52bc0fa35591a872fb4aac81f606e265c (diff)
parentfd9c1b962ae29ff928c2c6310a227b56b9db19bd (diff)
downloadrust-2e54f7f0a191a9319bf95f18810d48bd6c200e7e.tar.gz
rust-2e54f7f0a191a9319bf95f18810d48bd6c200e7e.zip
Rollup merge of #142569 - xizheyin:139253, r=davidtwco
Suggest clone in user-write-code instead of inside macro

Fixes rust-lang/rust#139253

Inspired by rust-lang/rust#142543

r? ````@fmease````
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
index dd6eb73a3a0..d18f4e03d2f 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
@@ -1302,8 +1302,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 None => ".clone()".to_string(),
             };
 
+            let span = expr.span.find_oldest_ancestor_in_same_ctxt().shrink_to_hi();
+
             diag.span_suggestion_verbose(
-                expr.span.shrink_to_hi(),
+                span,
                 "consider using clone here",
                 suggestion,
                 Applicability::MachineApplicable,