mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
tests: Add borrowck/var-matching-lifetime-but-unused-not-mentioned.rs
So that the impact of the commit that fixes the test can be seen clearly.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
//! Regression test for <https://github.com/rust-lang/rust/issues/113121>.
|
||||
|
||||
#![allow(unused_variables)]
|
||||
|
||||
fn consume<T: 'static>(_: T) {}
|
||||
|
||||
fn foo<'a>(
|
||||
used_arg: &'a u8,
|
||||
unused_arg: &'static u16, // Unused in closure. Must not appear in error.
|
||||
) {
|
||||
let unused_var: &'static u32 = &42; // Unused in closure. Must not appear in error.
|
||||
|
||||
let c = move || used_arg;
|
||||
consume(c); //~ ERROR: borrowed data escapes outside of function
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,19 @@
|
||||
error[E0521]: borrowed data escapes outside of function
|
||||
--> $DIR/var-matching-lifetime-but-unused-not-mentioned.rs:14:5
|
||||
|
|
||||
LL | fn foo<'a>(
|
||||
| -- lifetime `'a` defined here
|
||||
LL | used_arg: &'a u8,
|
||||
| -------- `used_arg` is a reference that is only valid in the function body
|
||||
LL | unused_arg: &'static u16, // Unused in closure. Must not appear in error.
|
||||
| ---------- `unused_arg` declared here, outside of the function body
|
||||
...
|
||||
LL | consume(c);
|
||||
| ^^^^^^^^^^
|
||||
| |
|
||||
| `used_arg` escapes the function body here
|
||||
| argument requires that `'a` must outlive `'static`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0521`.
|
||||
Reference in New Issue
Block a user