fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
1.3 KiB43 linesraw
1// run-rustfix
2//
3#![allow(warnings)]
4struct Wrapper<'a, T: ?Sized>(&'a T);
5
6trait Project {
7    type Projected<'a> where Self: 'a;
8    fn project(this: Wrapper<'_, Self>) -> Self::Projected<'_>;
9}
10trait MyTrait {}
11trait ProjectedMyTrait {}
12
13impl<T> Project for Option<T> {
14    type Projected<'a> = Option<Wrapper<'a, T>> where T: 'a;
15    fn project(this: Wrapper<'_, Self>) -> Self::Projected<'_> {
16        this.0.as_ref().map(Wrapper)
17    }
18}
19
20impl<T: MyTrait> MyTrait for Option<Wrapper<'_, T>> {}
21
22impl<T: ProjectedMyTrait> MyTrait for Wrapper<'_, T> {}
23
24impl<T> ProjectedMyTrait for T
25    where
26        T: Project,
27        for<'a> T::Projected<'a>: MyTrait,
28        //~^ NOTE due to current limitations in the borrow checker, this implies a `'static` lifetime
29        //~| NOTE due to current limitations in the borrow checker, this implies a `'static` lifetime
30{}
31
32fn require_trait<T: MyTrait>(_: T) {}
33
34fn foo<T : MyTrait + 'static + 'static, U : MyTrait + 'static + 'static>(wrap: Wrapper<'_, Option<T>>, wrap1: Wrapper<'_, Option<U>>) {
35    //~^ HELP consider restricting the type parameter to the `'static` lifetime
36    //~| HELP consider restricting the type parameter to the `'static` lifetime
37    require_trait(wrap);
38    //~^ ERROR `T` does not live long enough
39    require_trait(wrap1);
40    //~^ ERROR `U` does not live long enough
41}
42
43fn main() {}