Skip to content

Commit e341bf0

Browse files
jdonszelmannm-ou-se
andcommitted
Don't name variables from external macros in borrow errors.
Co-authored-by: Mara Bos <[email protected]>
1 parent e4567ab commit e341bf0

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
317317
opt: DescribePlaceOpt,
318318
) -> Option<String> {
319319
let local = place.local;
320+
if self.body.local_decls[local]
321+
.source_info
322+
.span
323+
.in_external_macro(self.infcx.tcx.sess.source_map())
324+
{
325+
return None;
326+
}
327+
320328
let mut autoderef_index = None;
321329
let mut buf = String::new();
322330
let mut ok = self.append_local_to_string(local, &mut buf);

src/doc/nomicon

src/gcc

Submodule gcc updated 29018 files

tests/ui/macros/auxiliary/return_from_external_macro.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ macro_rules! foo {
99
}
1010
};
1111
}
12-
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)