Skip to content

Don't refer to 'local binding' in extern macro. #142025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/return_from_external_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/macros/return_from_external_macro.stderr
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
Loading