]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-93341.rs
Move some tests with compare-mode=nll output to revisions
[rust.git] / src / test / ui / generic-associated-types / issue-93341.rs
1 // check-pass
2
3 #![feature(generic_associated_types)]
4 use std::marker::PhantomData;
5
6 pub struct Id<'id>(PhantomData<fn(&'id ()) -> &'id ()>);
7
8 fn new_id() -> Id<'static> {
9     Id(PhantomData)
10 }
11
12 pub trait HasLifetime where {
13     type AtLifetime<'a>;
14 }
15
16 pub struct ExistentialLifetime<S: HasLifetime>(S::AtLifetime<'static>);
17
18 impl<S: HasLifetime> ExistentialLifetime<S> {
19     pub fn new<F>(f: F) -> ExistentialLifetime<S>
20         where for<'id> F: FnOnce(Id<'id>) -> S::AtLifetime<'id> {
21         ExistentialLifetime(f(new_id()))
22     }
23 }
24
25
26 struct ExampleS<'id>(Id<'id>);
27
28 struct ExampleMarker;
29
30 impl HasLifetime for ExampleMarker {
31     type AtLifetime<'id> = ExampleS<'id>;
32 }
33
34
35 fn broken0() -> ExistentialLifetime<ExampleMarker> {
36     fn new_helper<'id>(id: Id<'id>) -> ExampleS<'id> {
37         ExampleS(id)
38     }
39
40     ExistentialLifetime::<ExampleMarker>::new(new_helper)
41 }
42
43 fn broken1() -> ExistentialLifetime<ExampleMarker> {
44     fn new_helper<'id>(id: Id<'id>) -> <ExampleMarker as HasLifetime>::AtLifetime<'id> {
45         ExampleS(id)
46     }
47
48     ExistentialLifetime::<ExampleMarker>::new(new_helper)
49 }
50
51 fn broken2() -> ExistentialLifetime<ExampleMarker> {
52     ExistentialLifetime::<ExampleMarker>::new(|id| ExampleS(id))
53 }
54
55 fn main() {}