]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-70304.rs
Rollup merge of #99651 - compiler-errors:fn-and-raw-ptr-in-const-generics, r=oli-obk
[rust.git] / src / test / ui / generic-associated-types / issue-70304.rs
1 #![feature(generic_associated_types)]
2
3 trait Document {
4     type Cursor<'a>: DocCursor<'a>;
5     //~^ ERROR: missing required bound on `Cursor`
6
7     fn cursor(&self) -> Self::Cursor<'_>;
8 }
9
10 struct DocumentImpl {}
11
12 impl Document for DocumentImpl {
13     type Cursor<'a> = DocCursorImpl<'a>;
14
15     fn cursor(&self) -> Self::Cursor<'_> {
16         DocCursorImpl { document: &self }
17     }
18 }
19
20 trait DocCursor<'a> {}
21
22 struct DocCursorImpl<'a> {
23     document: &'a DocumentImpl,
24 }
25
26 impl<'a> DocCursor<'a> for DocCursorImpl<'a> {}
27
28 struct Lexer<'d, Cursor>
29 where
30     Cursor: DocCursor<'d>,
31 {
32     cursor: Cursor,
33     _phantom: std::marker::PhantomData<&'d ()>,
34 }
35
36 impl<'d, Cursor> Lexer<'d, Cursor>
37 where
38     Cursor: DocCursor<'d>,
39 {
40     pub fn from<Doc>(document: &'d Doc) -> Lexer<'d, Cursor>
41     where
42         Doc: Document<Cursor<'d> = Cursor>,
43     {
44         Lexer { cursor: document.cursor(), _phantom: std::marker::PhantomData }
45     }
46 }
47
48 fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
49     //~^ ERROR `'_` cannot be used here [E0637]
50     //~| ERROR: missing lifetime specifier
51     DocumentImpl {}
52 }
53
54 pub fn main() {
55     let doc = create_doc();
56     let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
57 }