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