]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lifetimes/lifetime-bound-will-change-warning.rs
Merge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup
[rust.git] / src / test / 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) //~ ERROR mismatched types
35 }
36
37 fn test2cc<'a>(x: &'a Box<dyn Fn() + 'a>) {
38     // same as test2, but cross crate
39     lib::ref_obj(x) //~ ERROR mismatched types
40 }
41
42 fn test3<'a>(x: &'a Box<dyn Fn() + 'static>) {
43     // here, we have a 'static bound, so even when ref_obj changes, no error results
44     ref_obj(x)
45 }
46
47 fn test3cc<'a>(x: &'a Box<dyn Fn() + 'static>) {
48     // same as test3, but cross crate
49     lib::ref_obj(x)
50 }
51
52
53 fn main() {
54 }