about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-06-26 19:47:07 +0200
committerGitHub <noreply@github.com>2022-06-26 19:47:07 +0200
commit5efe7c7fc6333f10ead4f7775ccda12e19347917 (patch)
treea6876aaa7162f756414a35fac0b20369a6da375d /src
parent50b6e7db6a967552004871c097cd372d9dca5f57 (diff)
parent30724ebc175f7a9b03ae24f1eafb455dc77feb00 (diff)
downloadrust-5efe7c7fc6333f10ead4f7775ccda12e19347917.tar.gz
rust-5efe7c7fc6333f10ead4f7775ccda12e19347917.zip
Rollup merge of #98538 - TaKO8Ki:add-test-for-issue-91883, r=Mark-Simulacrum
Add a ui test for issue #91883

closes #91883
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/generic-associated-types/issue-91883.rs42
-rw-r--r--src/test/ui/generic-associated-types/issue-91883.stderr26
2 files changed, 68 insertions, 0 deletions
diff --git a/src/test/ui/generic-associated-types/issue-91883.rs b/src/test/ui/generic-associated-types/issue-91883.rs
new file mode 100644
index 00000000000..3d4585a44df
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-91883.rs
@@ -0,0 +1,42 @@
+#![feature(generic_associated_types)]
+
+use std::fmt::Debug;
+use std::marker::PhantomData;
+
+#[derive(Debug)]
+pub struct TransactionImpl<'db> {
+    _marker: PhantomData<&'db ()>,
+}
+
+#[derive(Debug)]
+pub struct CursorImpl<'txn> {
+    _marker: PhantomData<&'txn ()>,
+}
+
+pub trait Cursor<'txn> {}
+
+pub trait Transaction<'db>: Send + Sync + Debug + Sized {
+    type Cursor<'tx>: Cursor<'tx>
+    where
+        'db: 'tx,
+        Self: 'tx;
+
+    fn cursor<'tx>(&'tx self) -> Result<Self::Cursor<'tx>, ()>
+    where
+        'db: 'tx;
+}
+
+impl<'tx> Cursor<'tx> for CursorImpl<'tx> {}
+
+impl<'db> Transaction<'db> for TransactionImpl<'db> {
+    type Cursor<'tx> = CursorImpl<'tx>; //~ ERROR lifetime bound not satisfied
+
+    fn cursor<'tx>(&'tx self) -> Result<Self::Cursor<'tx>, ()>
+    where
+        'db: 'tx,
+    {
+        loop {}
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/generic-associated-types/issue-91883.stderr b/src/test/ui/generic-associated-types/issue-91883.stderr
new file mode 100644
index 00000000000..ed700876e02
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-91883.stderr
@@ -0,0 +1,26 @@
+error[E0478]: lifetime bound not satisfied
+  --> $DIR/issue-91883.rs:32:24
+   |
+LL | /     type Cursor<'tx>: Cursor<'tx>
+LL | |     where
+LL | |         'db: 'tx,
+LL | |         Self: 'tx;
+   | |__________________- definition of `Cursor` from trait
+...
+LL |       type Cursor<'tx> = CursorImpl<'tx>;
+   |                          ^^^^^^^^^^^^^^^- help: try copying these clauses from the trait: `where 'db: 'tx, Self: 'tx`
+   |
+note: lifetime parameter instantiated with the lifetime `'db` as defined here
+  --> $DIR/issue-91883.rs:31:6
+   |
+LL | impl<'db> Transaction<'db> for TransactionImpl<'db> {
+   |      ^^^
+note: but lifetime parameter must outlive the lifetime `'tx` as defined here
+  --> $DIR/issue-91883.rs:32:17
+   |
+LL |     type Cursor<'tx> = CursorImpl<'tx>;
+   |                 ^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0478`.