]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-70303.rs
Auto merge of #101629 - compiler-errors:issue-101623, r=sanxiyn
[rust.git] / src / test / ui / generic-associated-types / issue-70303.rs
1 // check-pass
2
3 trait Document {
4     type Cursor<'a>: DocCursor<'a> where Self: 'a;
5
6     fn cursor(&self) -> Self::Cursor<'_>;
7 }
8
9 struct DocumentImpl {}
10
11 impl Document for DocumentImpl {
12     type Cursor<'a> = DocCursorImpl<'a>;
13
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 {
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
54 pub fn main() {
55     let doc = DocumentImpl {};
56     let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
57 }