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:
Martin Nordholts
2026-04-01 06:29:14 +02:00
parent a40ea0af41
commit 7a092c466a
2 changed files with 36 additions and 0 deletions
@@ -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`.