Skip to content

Commit e4567ab

Browse files
committed
Test that names of variables in external macros are not shown on a borrow error
1 parent f97b3c6 commit e4567ab

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(super_let)]
2+
3+
#[macro_export]
4+
macro_rules! foo {
5+
() => {
6+
{
7+
super let args = 1;
8+
&args
9+
}
10+
};
11+
}
12+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ aux-crate: ret_from_ext=return_from_external_macro.rs
2+
3+
#![feature(super_let)]
4+
extern crate ret_from_ext;
5+
6+
fn foo() -> impl Sized {
7+
drop(|| ret_from_ext::foo!());
8+
//~^ ERROR cannot return reference to local binding
9+
10+
ret_from_ext::foo!()
11+
//~^ ERROR temporary value dropped while borrowed
12+
}
13+
//~^ NOTE temporary value is freed at the end of this statement
14+
15+
fn main() {
16+
foo();
17+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0515]: cannot return reference to local variable `args`
2+
--> $DIR/return_from_external_macro.rs:7:13
3+
|
4+
LL | drop(|| ret_from_ext::foo!());
5+
| ^^^^^^^^^^^^^^^^^^^^ returns a reference to data owned by the current function
6+
|
7+
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error[E0597]: `args` does not live long enough
10+
--> $DIR/return_from_external_macro.rs:10:5
11+
|
12+
LL | ret_from_ext::foo!()
13+
| ^^^^^^^^^^^^^^^^^^^^
14+
| |
15+
| borrowed value does not live long enough
16+
| binding `args` declared here
17+
| opaque type requires that `args` is borrowed for `'static`
18+
LL |
19+
LL | }
20+
| - `args` dropped here while still borrowed
21+
|
22+
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
23+
24+
error: aborting due to 2 previous errors
25+
26+
Some errors have detailed explanations: E0515, E0597.
27+
For more information about an error, try `rustc --explain E0515`.

0 commit comments

Comments
 (0)