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