Skip to content

Commit 7742371

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 c912d6f commit 7742371

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
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/issues/issue-27592.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ impl ::std::fmt::Write for Stream {
1515
fn main() {
1616
write(|| format_args!("{}", String::from("Hello world")));
1717
//~^ ERROR cannot return value referencing temporary value
18-
//~| ERROR cannot return reference to local binding
18+
//~| ERROR cannot return reference to temporary value
1919
}

tests/ui/issues/issue-27592.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | write(|| format_args!("{}", String::from("Hello world")));
77
| | temporary value created here
88
| returns a value referencing data owned by the current function
99

10-
error[E0515]: cannot return reference to local binding
10+
error[E0515]: cannot return reference to temporary value
1111
--> $DIR/issue-27592.rs:16:14
1212
|
1313
LL | write(|| format_args!("{}", String::from("Hello world")));

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)