From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../lifetime-bound-will-change-warning.rs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/ui/lifetimes/lifetime-bound-will-change-warning.rs (limited to 'tests/ui/lifetimes/lifetime-bound-will-change-warning.rs') diff --git a/tests/ui/lifetimes/lifetime-bound-will-change-warning.rs b/tests/ui/lifetimes/lifetime-bound-will-change-warning.rs new file mode 100644 index 000000000..0d0303705 --- /dev/null +++ b/tests/ui/lifetimes/lifetime-bound-will-change-warning.rs @@ -0,0 +1,56 @@ +// aux-build:lifetime_bound_will_change_warning_lib.rs + +// Test that various corner cases cause an error. These are tests +// that used to pass before we tweaked object defaults. + +#![allow(dead_code)] +#![allow(unused_variables)] + + +extern crate lifetime_bound_will_change_warning_lib as lib; + +fn just_ref(x: &dyn Fn()) { +} + +fn ref_obj(x: &Box) { + // this will change to &Box... + + // Note: no warning is issued here, because the type of `x` will change to 'static + if false { ref_obj(x); } +} + +fn test1<'a>(x: &'a Box) { + // just_ref will stay the same. + just_ref(&**x) +} + +fn test1cc<'a>(x: &'a Box) { + // same as test1, but cross-crate + lib::just_ref(&**x) +} + +fn test2<'a>(x: &'a Box) { + // but ref_obj will not, so warn. + ref_obj(x) + //~^ ERROR borrowed data escapes +} + +fn test2cc<'a>(x: &'a Box) { + // same as test2, but cross crate + lib::ref_obj(x) + //~^ ERROR borrowed data escapes +} + +fn test3<'a>(x: &'a Box) { + // here, we have a 'static bound, so even when ref_obj changes, no error results + ref_obj(x) +} + +fn test3cc<'a>(x: &'a Box) { + // same as test3, but cross crate + lib::ref_obj(x) +} + + +fn main() { +} -- cgit v1.2.3