]> git.proxmox.com Git - rustc.git/blame - src/test/ui/generic-associated-types/issue-70304.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / generic-associated-types / issue-70304.rs
CommitLineData
cdc7bbd5
XL
1#![feature(generic_associated_types)]
2
3trait Document {
4 type Cursor<'a>: DocCursor<'a>;
5
6 fn cursor(&self) -> Self::Cursor<'_>;
7}
8
9struct DocumentImpl {}
10
11impl 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
22trait DocCursor<'a> {}
23
24struct DocCursorImpl<'a> {
25 document: &'a DocumentImpl,
26}
27
28impl<'a> DocCursor<'a> for DocCursorImpl<'a> {}
29
30struct Lexer<'d, Cursor>
31where
32 Cursor: DocCursor<'d>,
33{
34 cursor: Cursor,
35 _phantom: std::marker::PhantomData<&'d ()>,
36}
37
38
39impl<'d, Cursor> Lexer<'d, Cursor>
40where
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
54fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
55 //~^ ERROR: missing lifetime specifier
56 DocumentImpl {}
57}
58
59pub fn main() {
60 let doc = create_doc();
61 let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
62}