From 7a092c466a4d5b4e1a57c0086e565dcec8ce51ba Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Wed, 1 Apr 2026 06:29:14 +0200 Subject: [PATCH] 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. --- ...ching-lifetime-but-unused-not-mentioned.rs | 17 +++++++++++++++++ ...g-lifetime-but-unused-not-mentioned.stderr | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/ui/borrowck/var-matching-lifetime-but-unused-not-mentioned.rs create mode 100644 tests/ui/borrowck/var-matching-lifetime-but-unused-not-mentioned.stderr diff --git a/tests/ui/borrowck/var-matching-lifetime-but-unused-not-mentioned.rs b/tests/ui/borrowck/var-matching-lifetime-but-unused-not-mentioned.rs new file mode 100644 index 000000000000..143b863bb6dd --- /dev/null +++ b/tests/ui/borrowck/var-matching-lifetime-but-unused-not-mentioned.rs @@ -0,0 +1,17 @@ +//! Regression test for . + +#![allow(unused_variables)] + +fn consume(_: 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() {} diff --git a/tests/ui/borrowck/var-matching-lifetime-but-unused-not-mentioned.stderr b/tests/ui/borrowck/var-matching-lifetime-but-unused-not-mentioned.stderr new file mode 100644 index 000000000000..e1dd259a6b02 --- /dev/null +++ b/tests/ui/borrowck/var-matching-lifetime-but-unused-not-mentioned.stderr @@ -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`.