2015-06-17 09:08:26 -05:00
|
|
|
// aux-build:lifetime_bound_will_change_warning_lib.rs
|
|
|
|
|
2015-07-14 18:36:15 -05:00
|
|
|
// Test that various corner cases cause an error. These are tests
|
|
|
|
// that used to pass before we tweaked object defaults.
|
2015-06-17 09:08:26 -05:00
|
|
|
|
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_variables)]
|
2018-10-30 18:18:11 -05:00
|
|
|
|
2015-06-17 09:08:26 -05:00
|
|
|
|
|
|
|
extern crate lifetime_bound_will_change_warning_lib as lib;
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn just_ref(x: &dyn Fn()) {
|
2015-06-17 09:08:26 -05:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn ref_obj(x: &Box<dyn Fn()>) {
|
2015-06-17 09:08:26 -05:00
|
|
|
// this will change to &Box<Fn()+'static>...
|
|
|
|
|
|
|
|
// Note: no warning is issued here, because the type of `x` will change to 'static
|
|
|
|
if false { ref_obj(x); }
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn test1<'a>(x: &'a Box<dyn Fn() + 'a>) {
|
2015-06-17 09:08:26 -05:00
|
|
|
// just_ref will stay the same.
|
|
|
|
just_ref(&**x)
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn test1cc<'a>(x: &'a Box<dyn Fn() + 'a>) {
|
2015-06-17 09:08:26 -05:00
|
|
|
// same as test1, but cross-crate
|
|
|
|
lib::just_ref(&**x)
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn test2<'a>(x: &'a Box<dyn Fn() + 'a>) {
|
2015-06-17 09:08:26 -05:00
|
|
|
// but ref_obj will not, so warn.
|
2022-05-22 01:05:15 -05:00
|
|
|
ref_obj(x)
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR borrowed data escapes
|
2015-06-17 09:08:26 -05:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn test2cc<'a>(x: &'a Box<dyn Fn() + 'a>) {
|
2015-06-17 09:08:26 -05:00
|
|
|
// same as test2, but cross crate
|
2022-05-22 01:05:15 -05:00
|
|
|
lib::ref_obj(x)
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR borrowed data escapes
|
2015-06-17 09:08:26 -05:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn test3<'a>(x: &'a Box<dyn Fn() + 'static>) {
|
2015-06-17 09:08:26 -05:00
|
|
|
// here, we have a 'static bound, so even when ref_obj changes, no error results
|
|
|
|
ref_obj(x)
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn test3cc<'a>(x: &'a Box<dyn Fn() + 'static>) {
|
2015-06-17 09:08:26 -05:00
|
|
|
// same as test3, but cross crate
|
|
|
|
lib::ref_obj(x)
|
|
|
|
}
|
|
|
|
|
2018-10-30 18:18:11 -05:00
|
|
|
|
2015-07-14 18:36:15 -05:00
|
|
|
fn main() {
|
2015-06-17 09:08:26 -05:00
|
|
|
}
|