about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2025-06-04 15:02:31 +0200
committerMara Bos <m-ou.se@m-ou.se>2025-06-04 15:07:47 +0200
commitfcfa9b0ba00cfeb17f050f26428aebe770cb4417 (patch)
tree0e5e8c33873fd6d2affc647e0458d917c9d43a56
parentd9a739363878a06633eb912e44f02a3c5d6ba08c (diff)
downloadrust-fcfa9b0ba00cfeb17f050f26428aebe770cb4417.tar.gz
rust-fcfa9b0ba00cfeb17f050f26428aebe770cb4417.zip
Don't refer to 'local binding' in extern macro.
The user has no clue what 'local binding' the compiler is talking about,
if they don't know the expansion of the macro.
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs8
-rw-r--r--tests/ui/macros/return_from_external_macro.rs2
-rw-r--r--tests/ui/macros/return_from_external_macro.stderr4
3 files changed, 10 insertions, 4 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index 3b7d31b1b13..b7b6a2da549 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -3314,7 +3314,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
                     "function parameter".to_string(),
                     "function parameter borrowed here".to_string(),
                 ),
-                LocalKind::Temp if self.body.local_decls[local].is_user_variable() => {
+                LocalKind::Temp
+                    if self.body.local_decls[local].is_user_variable()
+                        && !self.body.local_decls[local]
+                            .source_info
+                            .span
+                            .in_external_macro(self.infcx.tcx.sess.source_map()) =>
+                {
                     ("local binding".to_string(), "local binding introduced here".to_string())
                 }
                 LocalKind::ReturnPointer | LocalKind::Temp => {
diff --git a/tests/ui/macros/return_from_external_macro.rs b/tests/ui/macros/return_from_external_macro.rs
index 43fe99e63ad..91d0c4c64fd 100644
--- a/tests/ui/macros/return_from_external_macro.rs
+++ b/tests/ui/macros/return_from_external_macro.rs
@@ -5,7 +5,7 @@ extern crate ret_from_ext;
 
 fn foo() -> impl Sized {
     drop(|| ret_from_ext::foo!());
-    //~^ ERROR cannot return reference to local binding
+    //~^ ERROR cannot return reference to temporary value
 
     ret_from_ext::foo!()
     //~^ ERROR temporary value dropped while borrowed
diff --git a/tests/ui/macros/return_from_external_macro.stderr b/tests/ui/macros/return_from_external_macro.stderr
index b6010b8ec79..6f707b9f52b 100644
--- a/tests/ui/macros/return_from_external_macro.stderr
+++ b/tests/ui/macros/return_from_external_macro.stderr
@@ -1,11 +1,11 @@
-error[E0515]: cannot return reference to local binding
+error[E0515]: cannot return reference to temporary value
   --> $DIR/return_from_external_macro.rs:7:13
    |
 LL |     drop(|| ret_from_ext::foo!());
    |             ^^^^^^^^^^^^^^^^^^^^
    |             |
    |             returns a reference to data owned by the current function
-   |             local binding introduced here
+   |             temporary value created here
    |
    = note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)