|
| 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 | +#![allow(dead_code)] |
| 12 | + |
| 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"; |
| 16 | + |
| 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"; |
| 20 | + |
| 21 | +// a function that elides to an unbound lifetime for both in- and output |
| 22 | +fn id_u8_slice(arg: &[u8]) -> &[u8] { arg } |
| 23 | + |
| 24 | +// one with a function, argument elided |
| 25 | +static SOME_STATIC_SIMPLE_FN : &fn(&[u8]) -> &[u8] = id_u8_slice; |
| 26 | +const SOME_CONST_SIMPLE_FN : &fn(&[u8]) -> &[u8] = id_u8_slice; |
| 27 | + |
| 28 | +// this should be the same as without elision |
| 29 | +static SOME_STATIC_NON_ELIDED_fN : &fn<'a>(&'a [u8]) -> &'a [u8] = id_u8_slice; |
| 30 | +const SOME_CONST_NON_ELIDED_fN : &fn<'a>(&'a [u8]) -> &'a [u8] = id_u8_slice; |
| 31 | + |
| 32 | +// another function that elides, each to a different unbound lifetime |
| 33 | +fn multi_args(a: &u8, b: &u8, c: &u8) { } |
| 34 | + |
| 35 | +static SOME_STATIC_MULTI_FN : &fn(&u8, &u8, &u8) = multi_args; |
| 36 | +const SOME_CONST_MULTI_FN : &fn(&u8, &u8, &u8) = multi_args; |
| 37 | + |
| 38 | + |
| 39 | +fn main() { |
| 40 | + // make sure that the lifetime is actually elided (and not defaulted) |
| 41 | + let x = &[1u8, 2, 3]; |
| 42 | + SOME_STATIC_SIMPLE_FN(x); |
| 43 | + SOME_CONST_SIMPLE_FN(x); |
| 44 | + |
| 45 | + // make sure this works with different lifetimes |
| 46 | + let a = &1; |
| 47 | + { |
| 48 | + let b = &2; |
| 49 | + let c = &3; |
| 50 | + SOME_CONST_MULTI_FN(a, b, c); |
| 51 | + } |
| 52 | +} |
0 commit comments