|
11 | 11 | #![allow(dead_code)] |
12 | 12 |
|
13 | 13 | // very simple test for a 'static static with default lifetime |
14 | | -static SOME_STATIC_STR : &str = "&'static str"; |
15 | | -const SOME_CONST_STR : &str = "&'static str"; |
| 14 | +static STATIC_STR : &str = "&'static str"; |
| 15 | +const CONST_STR : &str = "&'static str"; |
16 | 16 |
|
17 | 17 | // this should be the same as without default: |
18 | | -static SOME_EXPLICIT_STATIC_STR : &'static str = "&'static str"; |
19 | | -const SOME_EXPLICIT_CONST_STR : &'static str = "&'static str"; |
| 18 | +static EXPLICIT_STATIC_STR : &'static str = "&'static str"; |
| 19 | +const EXPLICIT_CONST_STR : &'static str = "&'static str"; |
20 | 20 |
|
21 | 21 | // a function that elides to an unbound lifetime for both in- and output |
22 | 22 | fn id_u8_slice(arg: &[u8]) -> &[u8] { arg } |
23 | 23 |
|
24 | 24 | // one with a function, argument elided |
25 | | -static SOME_STATIC_SIMPLE_FN : &fn(&[u8]) -> &[u8] = |
| 25 | +static STATIC_SIMPLE_FN : &fn(&[u8]) -> &[u8] = |
26 | 26 | &(id_u8_slice as fn(&[u8]) -> &[u8]); |
27 | | -const SOME_CONST_SIMPLE_FN : &fn(&[u8]) -> &[u8] = |
| 27 | +const CONST_SIMPLE_FN : &fn(&[u8]) -> &[u8] = |
28 | 28 | &(id_u8_slice as fn(&[u8]) -> &[u8]); |
29 | 29 |
|
30 | 30 | // this should be the same as without elision |
31 | | -static SOME_STATIC_NON_ELIDED_fN : &for<'a> fn(&'a [u8]) -> &'a [u8] = |
| 31 | +static STATIC_NON_ELIDED_fN : &for<'a> fn(&'a [u8]) -> &'a [u8] = |
32 | 32 | &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]); |
33 | | -const SOME_CONST_NON_ELIDED_fN : &for<'a> fn(&'a [u8]) -> &'a [u8] = |
| 33 | +const CONST_NON_ELIDED_fN : &for<'a> fn(&'a [u8]) -> &'a [u8] = |
34 | 34 | &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]); |
35 | 35 |
|
36 | 36 | // another function that elides, each to a different unbound lifetime |
37 | 37 | fn multi_args(a: &u8, b: &u8, c: &u8) { } |
38 | 38 |
|
39 | | -static SOME_STATIC_MULTI_FN : &fn(&u8, &u8, &u8) = |
| 39 | +static STATIC_MULTI_FN : &fn(&u8, &u8, &u8) = |
40 | 40 | &(multi_args as fn(&u8, &u8, &u8)); |
41 | | -const SOME_CONST_MULTI_FN : &fn(&u8, &u8, &u8) = |
| 41 | +const CONST_MULTI_FN : &fn(&u8, &u8, &u8) = |
42 | 42 | &(multi_args as fn(&u8, &u8, &u8)); |
43 | 43 |
|
| 44 | +struct Foo<'a> { |
| 45 | + bools: &'a [bool] |
| 46 | +} |
| 47 | + |
| 48 | +static STATIC_FOO : Foo = Foo { bools: &[true, false] }; |
| 49 | +const CONST_FOO : Foo = Foo { bools: &[true, false] }; |
| 50 | + |
| 51 | +type Bar<'a> = Foo<'a>; |
| 52 | + |
| 53 | +static STATIC_BAR : Bar = Bar { bools: &[true, false] }; |
| 54 | +const CONST_BAR : Bar = Bar { bools: &[true, false] }; |
| 55 | + |
| 56 | +type Baz<'a> = fn(&'a [u8]) -> Option<u8>; |
| 57 | + |
| 58 | +fn baz(e: &[u8]) -> Option<u8> { e.first().map(|x| *x) } |
| 59 | + |
| 60 | +static STATIC_BAZ : &Baz = &(baz as Baz); |
| 61 | +const CONST_BAZ : &Baz = &(baz as Baz); |
| 62 | + |
| 63 | +static BYTES : &[u8] = &[1, 2, 3]; |
44 | 64 |
|
45 | 65 | fn main() { |
46 | 66 | // make sure that the lifetime is actually elided (and not defaulted) |
47 | 67 | let x = &[1u8, 2, 3]; |
48 | | - SOME_STATIC_SIMPLE_FN(x); |
49 | | - SOME_CONST_SIMPLE_FN(x); |
| 68 | + STATIC_SIMPLE_FN(x); |
| 69 | + CONST_SIMPLE_FN(x); |
| 70 | + |
| 71 | + let y = &[1u8, 2, 3]; |
| 72 | + STATIC_BAZ(BYTES); |
| 73 | + //CONST_BAZ(y); // strangely enough, this fails |
50 | 74 |
|
51 | 75 | // make sure this works with different lifetimes |
52 | 76 | let a = &1; |
53 | 77 | { |
54 | 78 | let b = &2; |
55 | 79 | let c = &3; |
56 | | - SOME_CONST_MULTI_FN(a, b, c); |
| 80 | + CONST_MULTI_FN(a, b, c); |
57 | 81 | } |
58 | 82 | } |
0 commit comments