]> git.proxmox.com Git - rustc.git/blob - tests/ui/lifetimes/lifetime-bound-will-change-warning.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / lifetimes / lifetime-bound-will-change-warning.rs
1 // aux-build:lifetime_bound_will_change_warning_lib.rs
2
3 // Test that various corner cases cause an error. These are tests
4 // that used to pass before we tweaked object defaults.
5
6 #![allow(dead_code)]
7 #![allow(unused_variables)]
8
9
10 extern crate lifetime_bound_will_change_warning_lib as lib;
11
12 fn just_ref(x: &dyn Fn()) {
13 }
14
15 fn ref_obj(x: &Box<dyn Fn()>) {
16 // this will change to &Box<Fn()+'static>...
17
18 // Note: no warning is issued here, because the type of `x` will change to 'static
19 if false { ref_obj(x); }
20 }
21
22 fn test1<'a>(x: &'a Box<dyn Fn() + 'a>) {
23 // just_ref will stay the same.
24 just_ref(&**x)
25 }
26
27 fn test1cc<'a>(x: &'a Box<dyn Fn() + 'a>) {
28 // same as test1, but cross-crate
29 lib::just_ref(&**x)
30 }
31
32 fn test2<'a>(x: &'a Box<dyn Fn() + 'a>) {
33 // but ref_obj will not, so warn.
34 ref_obj(x)
35 //~^ ERROR borrowed data escapes
36 }
37
38 fn test2cc<'a>(x: &'a Box<dyn Fn() + 'a>) {
39 // same as test2, but cross crate
40 lib::ref_obj(x)
41 //~^ ERROR borrowed data escapes
42 }
43
44 fn test3<'a>(x: &'a Box<dyn Fn() + 'static>) {
45 // here, we have a 'static bound, so even when ref_obj changes, no error results
46 ref_obj(x)
47 }
48
49 fn test3cc<'a>(x: &'a Box<dyn Fn() + 'static>) {
50 // same as test3, but cross crate
51 lib::ref_obj(x)
52 }
53
54
55 fn main() {
56 }