]> git.proxmox.com Git - rustc.git/blame - src/test/ui/rfcs/rfc1623.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / rfcs / rfc1623.rs
CommitLineData
b7449926 1// run-pass
0bf4aa26 2#![allow(unused_variables)]
b7449926
XL
3#![allow(non_upper_case_globals)]
4
9e0c209e
SL
5#![allow(dead_code)]
6
7// very simple test for a 'static static with default lifetime
8static STATIC_STR: &str = "&'static str";
9const CONST_STR: &str = "&'static str";
10
11// this should be the same as without default:
12static EXPLICIT_STATIC_STR: &'static str = "&'static str";
13const EXPLICIT_CONST_STR: &'static str = "&'static str";
14
15// a function that elides to an unbound lifetime for both in- and output
16fn id_u8_slice(arg: &[u8]) -> &[u8] {
17 arg
18}
19
20// one with a function, argument elided
21static STATIC_SIMPLE_FN: &fn(&[u8]) -> &[u8] = &(id_u8_slice as fn(&[u8]) -> &[u8]);
22const CONST_SIMPLE_FN: &fn(&[u8]) -> &[u8] = &(id_u8_slice as fn(&[u8]) -> &[u8]);
23
24// this should be the same as without elision
25static STATIC_NON_ELIDED_fN: &for<'a> fn(&'a [u8]) -> &'a [u8] =
26 &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
27const CONST_NON_ELIDED_fN: &for<'a> fn(&'a [u8]) -> &'a [u8] =
28 &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
29
30// another function that elides, each to a different unbound lifetime
31fn multi_args(a: &u8, b: &u8, c: &u8) {}
32
33static STATIC_MULTI_FN: &fn(&u8, &u8, &u8) = &(multi_args as fn(&u8, &u8, &u8));
34const CONST_MULTI_FN: &fn(&u8, &u8, &u8) = &(multi_args as fn(&u8, &u8, &u8));
35
36struct Foo<'a> {
37 bools: &'a [bool],
38}
39
40static STATIC_FOO: Foo = Foo { bools: &[true, false] };
41const CONST_FOO: Foo = Foo { bools: &[true, false] };
42
43type Bar<'a> = Foo<'a>;
44
45static STATIC_BAR: Bar = Bar { bools: &[true, false] };
46const CONST_BAR: Bar = Bar { bools: &[true, false] };
47
48type Baz<'a> = fn(&'a [u8]) -> Option<u8>;
49
50fn baz(e: &[u8]) -> Option<u8> {
51 e.first().map(|x| *x)
52}
53
54static STATIC_BAZ: &Baz = &(baz as Baz);
55const CONST_BAZ: &Baz = &(baz as Baz);
56
57static BYTES: &[u8] = &[1, 2, 3];
58
59fn main() {
60 // make sure that the lifetime is actually elided (and not defaulted)
61 let x = &[1u8, 2, 3];
62 STATIC_SIMPLE_FN(x);
63 CONST_SIMPLE_FN(x);
64
65 STATIC_BAZ(BYTES); // neees static lifetime
66 CONST_BAZ(BYTES);
67
68 // make sure this works with different lifetimes
69 let a = &1;
70 {
71 let b = &2;
72 let c = &3;
73 CONST_MULTI_FN(a, b, c);
74 }
75}