Test that names of variables in external macros are not shown on a borrow error
This commit is contained in:
parent
f97b3c6044
commit
867b4c9e48
4 changed files with 65 additions and 0 deletions
|
|
@ -317,6 +317,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
opt: DescribePlaceOpt,
|
||||
) -> Option<String> {
|
||||
let local = place.local;
|
||||
if self.body.local_decls[local]
|
||||
.source_info
|
||||
.span
|
||||
.in_external_macro(self.infcx.tcx.sess.source_map())
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut autoderef_index = None;
|
||||
let mut buf = String::new();
|
||||
let mut ok = self.append_local_to_string(local, &mut buf);
|
||||
|
|
|
|||
11
tests/ui/macros/auxiliary/return_from_external_macro.rs
Normal file
11
tests/ui/macros/auxiliary/return_from_external_macro.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#![feature(super_let)]
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! foo {
|
||||
() => {
|
||||
{
|
||||
super let args = 1;
|
||||
&args
|
||||
}
|
||||
};
|
||||
}
|
||||
17
tests/ui/macros/return_from_external_macro.rs
Normal file
17
tests/ui/macros/return_from_external_macro.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
//@ aux-crate: ret_from_ext=return_from_external_macro.rs
|
||||
|
||||
#![feature(super_let)]
|
||||
extern crate ret_from_ext;
|
||||
|
||||
fn foo() -> impl Sized {
|
||||
drop(|| ret_from_ext::foo!());
|
||||
//~^ ERROR cannot return reference to local binding
|
||||
|
||||
ret_from_ext::foo!()
|
||||
//~^ ERROR temporary value dropped while borrowed
|
||||
}
|
||||
//~^ NOTE temporary value is freed at the end of this statement
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
}
|
||||
29
tests/ui/macros/return_from_external_macro.stderr
Normal file
29
tests/ui/macros/return_from_external_macro.stderr
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
error[E0515]: cannot return reference to local binding
|
||||
--> $DIR/return_from_external_macro.rs:7:13
|
||||
|
|
||||
LL | drop(|| ret_from_ext::foo!());
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| returns a reference to data owned by the current function
|
||||
| local binding introduced here
|
||||
|
|
||||
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/return_from_external_macro.rs:10:5
|
||||
|
|
||||
LL | ret_from_ext::foo!()
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| creates a temporary value which is freed while still in use
|
||||
| opaque type requires that borrow lasts for `'static`
|
||||
LL |
|
||||
LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
|
||||
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0515, E0716.
|
||||
For more information about an error, try `rustc --explain E0515`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue