Skip to content

Commit fcfa9b0

Browse files
committed
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.
1 parent d9a7393 commit fcfa9b0

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
33143314
"function parameter".to_string(),
33153315
"function parameter borrowed here".to_string(),
33163316
),
3317-
LocalKind::Temp if self.body.local_decls[local].is_user_variable() => {
3317+
LocalKind::Temp
3318+
if self.body.local_decls[local].is_user_variable()
3319+
&& !self.body.local_decls[local]
3320+
.source_info
3321+
.span
3322+
.in_external_macro(self.infcx.tcx.sess.source_map()) =>
3323+
{
33183324
("local binding".to_string(), "local binding introduced here".to_string())
33193325
}
33203326
LocalKind::ReturnPointer | LocalKind::Temp => {

tests/ui/macros/return_from_external_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate ret_from_ext;
55

66
fn foo() -> impl Sized {
77
drop(|| ret_from_ext::foo!());
8-
//~^ ERROR cannot return reference to local binding
8+
//~^ ERROR cannot return reference to temporary value
99

1010
ret_from_ext::foo!()
1111
//~^ ERROR temporary value dropped while borrowed

tests/ui/macros/return_from_external_macro.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0515]: cannot return reference to local binding
1+
error[E0515]: cannot return reference to temporary value
22
--> $DIR/return_from_external_macro.rs:7:13
33
|
44
LL | drop(|| ret_from_ext::foo!());
55
| ^^^^^^^^^^^^^^^^^^^^
66
| |
77
| returns a reference to data owned by the current function
8-
| local binding introduced here
8+
| temporary value created here
99
|
1010
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

0 commit comments

Comments
 (0)