2 #![allow(unused_variables)]
3 #![allow(non_upper_case_globals)]
7 // very simple test for a 'static static with default lifetime
8 static STATIC_STR: &str = "&'static str";
9 const CONST_STR: &str = "&'static str";
11 // this should be the same as without default:
12 static EXPLICIT_STATIC_STR: &'static str = "&'static str";
13 const EXPLICIT_CONST_STR: &'static str = "&'static str";
15 // a function that elides to an unbound lifetime for both in- and output
16 fn id_u8_slice(arg: &[u8]) -> &[u8] {
20 // one with a function, argument elided
21 static STATIC_SIMPLE_FN: &fn(&[u8]) -> &[u8] = &(id_u8_slice as fn(&[u8]) -> &[u8]);
22 const CONST_SIMPLE_FN: &fn(&[u8]) -> &[u8] = &(id_u8_slice as fn(&[u8]) -> &[u8]);
24 // this should be the same as without elision
25 static STATIC_NON_ELIDED_fN: &for<'a> fn(&'a [u8]) -> &'a [u8] =
26 &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
27 const CONST_NON_ELIDED_fN: &for<'a> fn(&'a [u8]) -> &'a [u8] =
28 &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
30 // another function that elides, each to a different unbound lifetime
31 fn multi_args(a: &u8, b: &u8, c: &u8) {}
33 static STATIC_MULTI_FN: &fn(&u8, &u8, &u8) = &(multi_args as fn(&u8, &u8, &u8));
34 const CONST_MULTI_FN: &fn(&u8, &u8, &u8) = &(multi_args as fn(&u8, &u8, &u8));
40 static STATIC_FOO: Foo = Foo { bools: &[true, false] };
41 const CONST_FOO: Foo = Foo { bools: &[true, false] };
43 type Bar<'a> = Foo<'a>;
45 static STATIC_BAR: Bar = Bar { bools: &[true, false] };
46 const CONST_BAR: Bar = Bar { bools: &[true, false] };
48 type Baz<'a> = fn(&'a [u8]) -> Option<u8>;
50 fn baz(e: &[u8]) -> Option<u8> {
54 static STATIC_BAZ: &Baz = &(baz as Baz);
55 const CONST_BAZ: &Baz = &(baz as Baz);
57 static BYTES: &[u8] = &[1, 2, 3];
60 // make sure that the lifetime is actually elided (and not defaulted)
65 STATIC_BAZ(BYTES); // neees static lifetime
68 // make sure this works with different lifetimes
73 CONST_MULTI_FN(a, b, c);