]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-70304.rs
Rollup merge of #102954 - GuillaumeGomez:cfg-hide-attr-checks, r=Manishearth
[rust.git] / src / test / ui / generic-associated-types / issue-70304.rs
1 trait Document {
2     type Cursor<'a>: DocCursor<'a>;
3     //~^ ERROR: missing required bound on `Cursor`
4
5     fn cursor(&self) -> Self::Cursor<'_>;
6 }
7
8 struct DocumentImpl {}
9
10 impl Document for DocumentImpl {
11     type Cursor<'a> = DocCursorImpl<'a>;
12
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 {
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
46 fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
47     //~^ ERROR `'_` cannot be used here [E0637]
48     //~| ERROR: missing lifetime specifier
49     DocumentImpl {}
50 }
51
52 pub fn main() {
53     let doc = create_doc();
54     let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
55 }