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