]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/lifetime-bound-will-change-warning.rs
Imported Upstream version 1.3.0+dfsg1
[rustc.git] / src / test / compile-fail / lifetime-bound-will-change-warning.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // aux-build:lifetime_bound_will_change_warning_lib.rs
12
13 // Test that various corner cases cause an error. These are tests
14 // that used to pass before we tweaked object defaults.
15
16 #![allow(dead_code)]
17 #![allow(unused_variables)]
18 #![feature(rustc_attrs)]
19
20 extern crate lifetime_bound_will_change_warning_lib as lib;
21
22 fn just_ref(x: &Fn()) {
23 }
24
25 fn ref_obj(x: &Box<Fn()>) {
26 // this will change to &Box<Fn()+'static>...
27
28 // Note: no warning is issued here, because the type of `x` will change to 'static
29 if false { ref_obj(x); }
30 }
31
32 fn test1<'a>(x: &'a Box<Fn()+'a>) {
33 // just_ref will stay the same.
34 just_ref(&**x)
35 }
36
37 fn test1cc<'a>(x: &'a Box<Fn()+'a>) {
38 // same as test1, but cross-crate
39 lib::just_ref(&**x)
40 }
41
42 fn test2<'a>(x: &'a Box<Fn()+'a>) {
43 // but ref_obj will not, so warn.
44 ref_obj(x) //~ ERROR mismatched types
45 }
46
47 fn test2cc<'a>(x: &'a Box<Fn()+'a>) {
48 // same as test2, but cross crate
49 lib::ref_obj(x) //~ ERROR mismatched types
50 }
51
52 fn test3<'a>(x: &'a Box<Fn()+'static>) {
53 // here, we have a 'static bound, so even when ref_obj changes, no error results
54 ref_obj(x)
55 }
56
57 fn test3cc<'a>(x: &'a Box<Fn()+'static>) {
58 // same as test3, but cross crate
59 lib::ref_obj(x)
60 }
61
62 #[rustc_error]
63 fn main() {
64 }