]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-53570.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / nll / issue-53570.rs
1 // Copyright 2018 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 // Regression test for #53570. Here, we need to propagate that `T: 'a`
12 // but in some versions of NLL we were propagating a stronger
13 // requirement that `T: 'static`. This arose because we actually had
14 // to propagate both that `T: 'a` but also `T: 'b` where `'b` is the
15 // higher-ranked lifetime that appears in the type of the closure
16 // parameter `x` -- since `'b` cannot be expressed in the caller's
17 // space, that got promoted th `'static`.
18 //
19 // compile-pass
20
21 #![feature(nll)]
22 #![feature(rustc_attrs)]
23 #![allow(dead_code)]
24
25 use std::cell::{RefCell, Ref};
26
27 trait AnyVec<'a> {
28 }
29
30 trait GenericVec<T> {
31     fn unwrap<'a, 'b>(vec: &'b AnyVec<'a>) -> &'b [T] where T: 'a;
32 }
33
34 struct Scratchpad<'a> {
35     buffers: RefCell<Box<AnyVec<'a>>>,
36 }
37
38 impl<'a> Scratchpad<'a> {
39     fn get<T: GenericVec<T>>(&self) -> Ref<[T]>
40     where T: 'a
41     {
42         Ref::map(self.buffers.borrow(), |x| T::unwrap(x.as_ref()))
43     }
44 }
45
46 fn main() { }