1 #![feature(generic_associated_types)]
2
3 trait Document {
4 type Cursor<'a>: DocCursor<'a>;
5
cursor(&self) -> Self::Cursor<'_>6 fn cursor(&self) -> Self::Cursor<'_>;
7 }
8
9 struct DocumentImpl {}
10
11 impl Document for DocumentImpl {
12 type Cursor<'a> = DocCursorImpl<'a>;
13
cursor(&self) -> Self::Cursor<'_>14 fn cursor(&self) -> Self::Cursor<'_> {
15 DocCursorImpl {
16 document: &self,
17 }
18 }
19 }
20
21
22 trait DocCursor<'a> {}
23
24 struct DocCursorImpl<'a> {
25 document: &'a DocumentImpl,
26 }
27
28 impl<'a> DocCursor<'a> for DocCursorImpl<'a> {}
29
30 struct Lexer<'d, Cursor>
31 where
32 Cursor: DocCursor<'d>,
33 {
34 cursor: Cursor,
35 _phantom: std::marker::PhantomData<&'d ()>,
36 }
37
38
39 impl<'d, Cursor> Lexer<'d, Cursor>
40 where
41 Cursor: DocCursor<'d>,
42 {
from<Doc>(document: &'d Doc) -> Lexer<'d, Cursor> where Doc: Document<Cursor<'d> = Cursor>,43 pub fn from<Doc>(document: &'d Doc) -> Lexer<'d, Cursor>
44 where
45 Doc: Document<Cursor<'d> = Cursor>,
46 {
47 Lexer {
48 cursor: document.cursor(),
49 _phantom: std::marker::PhantomData,
50 }
51 }
52 }
53
create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>>54 fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
55 //~^ ERROR: missing lifetime specifier
56 DocumentImpl {}
57 }
58
main()59 pub fn main() {
60 let doc = create_doc();
61 let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
62 }
63