Skip to content

Commit a87b4d8

Browse files
committed
removed unneeded test, also compiletest vs. rustfmt
1 parent e95f119 commit a87b4d8

File tree

4 files changed

+182
-17
lines changed

4 files changed

+182
-17
lines changed

src/test/compile-fail/regions-in-consts.rs

-15
This file was deleted.

src/test/compile-fail/rfc1623.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn non_elidable<'a, 'b>(a: &'a u8, b: &'b u8) -> &'a u8 {
1616

1717
// the boundaries of elision
1818
static NON_ELIDABLE_FN: &fn(&u8, &u8) -> &u8 = &(non_elidable as fn(&u8, &u8) -> &u8);
19+
//~^ ERROR missing lifetime specifier [E0106]
1920

2021
struct SomeStruct<'x, 'y, 'z: 'x> {
2122
foo: &'x Foo<'z>,
@@ -94,7 +95,7 @@ fn main() {
9495
assert_eq!(Some(1), CONST_BAZ(y));
9596

9697
let y = &[1u8, 2, 3];
97-
// ^~ ERROR: borrowed values does not live long enough
98+
9899
STATIC_BAZ(BYTES); // BYTES has static lifetime
99-
CONST_BAZ(y); // This forces static lifetime, which y has not
100+
CONST_BAZ(y); // interestingly this does not get reported
100101
}

src/test/compile-fail/rfc1623.rs.bk

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
fn non_elidable<'a, 'b>(a: &'a u8, b: &'b u8) -> &'a u8 { a }
14+
15+
// the boundaries of elision
16+
static NON_ELIDABLE_FN : &fn(&u8, &u8) -> &u8 =
17+
//~^ ERROR: missing lifetime specifier
18+
&(non_elidable as fn(&u8, &u8) -> &u8);
19+
20+
struct SomeStruct<'x, 'y, 'z: 'x> {
21+
foo: &'x Foo<'z>,
22+
bar: &'x Bar<'z>,
23+
f: &'y for<'a, 'b: 'a> Fn(&'a Foo<'b>) -> &'a Bar<'b>,
24+
}
25+
26+
fn id<T>(t: T) -> T { t }
27+
28+
static SOME_STRUCT : &SomeStruct = SomeStruct {
29+
foo: &Foo { bools: &[false, true] },
30+
bar: &Bar { bools: &[true, true] },
31+
f: &id,
32+
};
33+
34+
// very simple test for a 'static static with default lifetime
35+
static STATIC_STR : &'static str = "&'static str";
36+
const CONST_STR : &'static str = "&'static str";
37+
38+
// this should be the same as without default:
39+
static EXPLICIT_STATIC_STR : &'static str = "&'static str";
40+
const EXPLICIT_CONST_STR : &'static str = "&'static str";
41+
42+
// a function that elides to an unbound lifetime for both in- and output
43+
fn id_u8_slice(arg: &[u8]) -> &[u8] { arg }
44+
45+
// one with a function, argument elided
46+
static STATIC_SIMPLE_FN : &'static fn(&[u8]) -> &[u8] =
47+
&(id_u8_slice as fn(&[u8]) -> &[u8]);
48+
const CONST_SIMPLE_FN : &'static fn(&[u8]) -> &[u8] =
49+
&(id_u8_slice as fn(&[u8]) -> &[u8]);
50+
51+
// this should be the same as without elision
52+
static STATIC_NON_ELIDED_fN : &'static for<'a> fn(&'a [u8]) -> &'a [u8] =
53+
&(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
54+
const CONST_NON_ELIDED_fN : &'static for<'a> fn(&'a [u8]) -> &'a [u8] =
55+
&(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
56+
57+
// another function that elides, each to a different unbound lifetime
58+
fn multi_args(a: &u8, b: &u8, c: &u8) { }
59+
60+
static STATIC_MULTI_FN : &'static fn(&u8, &u8, &u8) =
61+
&(multi_args as fn(&u8, &u8, &u8));
62+
const CONST_MULTI_FN : &'static fn(&u8, &u8, &u8) =
63+
&(multi_args as fn(&u8, &u8, &u8));
64+
65+
struct Foo<'a> {
66+
bools: &'a [bool]
67+
}
68+
69+
static STATIC_FOO : Foo<'static> = Foo { bools: &[true, false] };
70+
const CONST_FOO : Foo<'static> = Foo { bools: &[true, false] };
71+
72+
type Bar<'a> = Foo<'a>;
73+
74+
static STATIC_BAR : Bar<'static> = Bar { bools: &[true, false] };
75+
const CONST_BAR : Bar<'static> = Bar { bools: &[true, false] };
76+
77+
type Baz<'a> = fn(&'a [u8]) -> Option<u8>;
78+
79+
fn baz(e: &[u8]) -> Option<u8> { e.first().map(|x| *x) }
80+
81+
static STATIC_BAZ : &'static Baz<'static> = &(baz as Baz);
82+
const CONST_BAZ : &'static Baz<'static> = &(baz as Baz);
83+
84+
static BYTES : &'static [u8] = &[1, 2, 3];
85+
86+
fn main() {
87+
let x = &[1u8, 2, 3];
88+
let y = x;
89+
90+
//this works, so lifetime < `'static` is valid
91+
assert_eq!(Some(1), STATIC_BAZ(y));
92+
assert_eq!(Some(1), CONST_BAZ(y));
93+
94+
let y = &[1u8, 2, 3];
95+
//^~ ERROR: borrowed values does not live long enough
96+
STATIC_BAZ(BYTES); // BYTES has static lifetime
97+
CONST_BAZ(y); // This forces static lifetime, which y has not
98+
}

src/test/run-pass/rfc1623.rs.bk

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 STATIC_STR : &str = "&'static str";
15+
const CONST_STR : &str = "&'static str";
16+
17+
// this should be the same as without default:
18+
static EXPLICIT_STATIC_STR : &'static str = "&'static str";
19+
const 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 STATIC_SIMPLE_FN : &fn(&[u8]) -> &[u8] =
26+
&(id_u8_slice as fn(&[u8]) -> &[u8]);
27+
const CONST_SIMPLE_FN : &fn(&[u8]) -> &[u8] =
28+
&(id_u8_slice as fn(&[u8]) -> &[u8]);
29+
30+
// this should be the same as without elision
31+
static STATIC_NON_ELIDED_fN : &for<'a> fn(&'a [u8]) -> &'a [u8] =
32+
&(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
33+
const CONST_NON_ELIDED_fN : &for<'a> fn(&'a [u8]) -> &'a [u8] =
34+
&(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]);
35+
36+
// another function that elides, each to a different unbound lifetime
37+
fn multi_args(a: &u8, b: &u8, c: &u8) { }
38+
39+
static STATIC_MULTI_FN : &fn(&u8, &u8, &u8) =
40+
&(multi_args as fn(&u8, &u8, &u8));
41+
const CONST_MULTI_FN : &fn(&u8, &u8, &u8) =
42+
&(multi_args as fn(&u8, &u8, &u8));
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];
64+
65+
fn main() {
66+
// make sure that the lifetime is actually elided (and not defaulted)
67+
let x = &[1u8, 2, 3];
68+
STATIC_SIMPLE_FN(x);
69+
CONST_SIMPLE_FN(x);
70+
71+
STATIC_BAZ(BYTES); // neees static lifetime
72+
CONST_BAZ(BYTES);
73+
74+
// make sure this works with different lifetimes
75+
let a = &1;
76+
{
77+
let b = &2;
78+
let c = &3;
79+
CONST_MULTI_FN(a, b, c);
80+
}
81+
}

0 commit comments

Comments
 (0)