about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authormarmeladema <xademax@gmail.com>2021-04-20 23:49:04 +0100
committermarmeladema <xademax@gmail.com>2021-04-20 23:49:35 +0100
commit1ef760d88e8cbbc73ca53598f8de5536d1fbfac9 (patch)
tree11a0547d65d9dfc2a443da745c7c7ff5489dff3a /src/test
parent25cb1af7b232c93396b122ed6eb0887a388183f7 (diff)
downloadrust-1ef760d88e8cbbc73ca53598f8de5536d1fbfac9.tar.gz
rust-1ef760d88e8cbbc73ca53598f8de5536d1fbfac9.zip
Add test for issue #70303
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/generic-associated-types/issue-70303.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/ui/generic-associated-types/issue-70303.rs b/src/test/ui/generic-associated-types/issue-70303.rs
new file mode 100644
index 00000000000..a1cb2295b63
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-70303.rs
@@ -0,0 +1,60 @@
+// check-pass
+
+#![allow(incomplete_features)]
+#![feature(generic_associated_types)]
+
+trait Document {
+    type Cursor<'a>: DocCursor<'a>;
+
+    fn cursor(&self) -> Self::Cursor<'_>;
+}
+
+struct DocumentImpl {}
+
+impl Document for DocumentImpl {
+    type Cursor<'a> = DocCursorImpl<'a>;
+
+    fn cursor(&self) -> Self::Cursor<'_> {
+        DocCursorImpl {
+            document: &self,
+        }
+    }
+}
+
+
+trait DocCursor<'a> {}
+
+struct DocCursorImpl<'a> {
+    document: &'a DocumentImpl,
+}
+
+impl<'a> DocCursor<'a> for DocCursorImpl<'a> {}
+
+struct Lexer<'d, Cursor>
+where
+    Cursor: DocCursor<'d>,
+{
+    cursor: Cursor,
+    _phantom: std::marker::PhantomData<&'d ()>,
+}
+
+
+impl<'d, Cursor> Lexer<'d, Cursor>
+where
+    Cursor: DocCursor<'d>,
+{
+    pub fn from<Doc>(document: &'d Doc) -> Lexer<'d, Cursor>
+    where
+        Doc: Document<Cursor<'d> = Cursor>,
+    {
+        Lexer {
+            cursor: document.cursor(),
+            _phantom: std::marker::PhantomData,
+        }
+    }
+}
+
+pub fn main() {
+    let doc = DocumentImpl {};
+    let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
+}