Skip to content

Commit 6144e11

Browse files
jdonszelmannm-ou-se
andcommitted
Don't name variables from external macros in borrow errors.
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
1 parent e4567ab commit 6144e11

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
317317
opt: DescribePlaceOpt,
318318
) -> Option<String> {
319319
let local = place.local;
320+
if self.body.local_decls[local].source_info.span.in_external_macro(self.infcx.tcx.sess.source_map()) {
321+
return None;
322+
}
323+
320324
let mut autoderef_index = None;
321325
let mut buf = String::new();
322326
let mut ok = self.append_local_to_string(local, &mut buf);
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
error[E0515]: cannot return reference to local variable `args`
1+
error[E0515]: cannot return reference to local binding
22
--> $DIR/return_from_external_macro.rs:7:13
33
|
44
LL | drop(|| ret_from_ext::foo!());
5-
| ^^^^^^^^^^^^^^^^^^^^ returns a reference to data owned by the current function
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| returns a reference to data owned by the current function
8+
| local binding introduced here
69
|
710
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
811

9-
error[E0597]: `args` does not live long enough
12+
error[E0716]: temporary value dropped while borrowed
1013
--> $DIR/return_from_external_macro.rs:10:5
1114
|
1215
LL | ret_from_ext::foo!()
1316
| ^^^^^^^^^^^^^^^^^^^^
1417
| |
15-
| borrowed value does not live long enough
16-
| binding `args` declared here
17-
| opaque type requires that `args` is borrowed for `'static`
18+
| creates a temporary value which is freed while still in use
19+
| opaque type requires that borrow lasts for `'static`
1820
LL |
1921
LL | }
20-
| - `args` dropped here while still borrowed
22+
| - temporary value is freed at the end of this statement
2123
|
2224
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
2325

2426
error: aborting due to 2 previous errors
2527

26-
Some errors have detailed explanations: E0515, E0597.
28+
Some errors have detailed explanations: E0515, E0716.
2729
For more information about an error, try `rustc --explain E0515`.

0 commit comments

Comments
 (0)