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