3 fn non_elidable<'a, 'b>(a: &'a u8, b: &'b u8) -> &'a u8 {
7 // The incorrect case without `for<'a>` is tested for in `rfc1623-2.rs`
8 static NON_ELIDABLE_FN: &for<'a> fn(&'a u8, &'a u8) -> &'a u8 =
9 &(non_elidable as for<'a> fn(&'a u8, &'a u8) -> &'a u8);
11 struct SomeStruct<'x, 'y, 'z: 'x> {
14 f: &'y dyn for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Foo<'b>,
21 static SOME_STRUCT: &SomeStruct = &SomeStruct {
22 foo: &Foo { bools: &[false, true] },
23 bar: &Bar { bools: &[true, true] },
25 //~^ ERROR implementation of `FnOnce` is not general enough
26 //~^^ mismatched types
27 //~^^^ mismatched types
28 //~^^^^ mismatched types
29 //~^^^^^ mismatched types
32 // very simple test for a 'static static with default lifetime
33 static STATIC_STR: &'static str = "&'static str";
34 const CONST_STR: &'static str = "&'static str";
36 // this should be the same as without default:
37 static EXPLICIT_STATIC_STR: &'static str = "&'static str";
38 const EXPLICIT_CONST_STR: &'static str = "&'static str";
40 // a function that elides to an unbound lifetime for both in- and output
41 fn id_u8_slice(arg: &[u8]) -> &[u8] {
45 // one with a function, argument elided
46 static STATIC_SIMPLE_FN: &'static fn(&[u8]) -> &[u8] = &(id_u8_slice as fn(&[u8]) -> &[u8]);
47 const CONST_SIMPLE_FN: &'static fn(&[u8]) -> &[u8] = &(id_u8_slice as fn(&[u8]) -> &[u8]);
49 // this should be the same as without elision
50 static STATIC_NON_ELIDED_fN: &'static for<'a> fn(&'a [u8]) -> &'a [u8] =
51 &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
52 const CONST_NON_ELIDED_fN: &'static for<'a> fn(&'a [u8]) -> &'a [u8] =
53 &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
55 // another function that elides, each to a different unbound lifetime
56 fn multi_args(a: &u8, b: &u8, c: &u8) {}
58 static STATIC_MULTI_FN: &'static fn(&u8, &u8, &u8) = &(multi_args as fn(&u8, &u8, &u8));
59 const CONST_MULTI_FN: &'static fn(&u8, &u8, &u8) = &(multi_args as fn(&u8, &u8, &u8));
65 static STATIC_FOO: Foo<'static> = Foo { bools: &[true, false] };
66 const CONST_FOO: Foo<'static> = Foo { bools: &[true, false] };
68 type Bar<'a> = Foo<'a>;
70 static STATIC_BAR: Bar<'static> = Bar { bools: &[true, false] };
71 const CONST_BAR: Bar<'static> = Bar { bools: &[true, false] };
73 type Baz<'a> = fn(&'a [u8]) -> Option<u8>;
75 fn baz(e: &[u8]) -> Option<u8> {
79 static STATIC_BAZ: &'static Baz<'static> = &(baz as Baz);
80 const CONST_BAZ: &'static Baz<'static> = &(baz as Baz);
82 static BYTES: &'static [u8] = &[1, 2, 3];
88 // this works, so lifetime < `'static` is valid
89 assert_eq!(Some(1), STATIC_BAZ(y));
90 assert_eq!(Some(1), CONST_BAZ(y));
94 STATIC_BAZ(BYTES); // BYTES has static lifetime
95 CONST_BAZ(y); // interestingly this does not get reported