]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/impl-trait/lifetimes.rs
Rollup merge of #35597 - tshepang:it-is-a-slice, r=steveklabnik
[rust.git] / src / test / compile-fail / impl-trait / lifetimes.rs
1 // Copyright 2016 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(conservative_impl_trait)]
12
13 // Helper creating a fake borrow, captured by the impl Trait.
14 fn borrow<'a, T>(_: &'a mut T) -> impl Copy { () }
15
16 fn stack() -> impl Copy {
17     //~^ ERROR only named lifetimes are allowed in `impl Trait`
18     let x = 0;
19     &x
20 }
21
22 fn late_bound(x: &i32) -> impl Copy {
23     //~^ ERROR only named lifetimes are allowed in `impl Trait`
24     x
25 }
26
27 // FIXME(#34511) Should work but doesn't at the moment,
28 // region-checking needs an overhault to support this.
29 fn early_bound<'a>(x: &'a i32) -> impl Copy {
30     //~^ ERROR only named lifetimes are allowed in `impl Trait`
31     x
32 }
33
34 fn ambiguous<'a, 'b>(x: &'a [u32], y: &'b [u32]) -> impl Iterator<Item=u32> {
35     //~^ ERROR only named lifetimes are allowed in `impl Trait`
36     if x.len() < y.len() {
37         x.iter().cloned()
38     } else {
39         y.iter().cloned()
40     }
41 }
42
43 fn main() {}