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`.