about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-05-23 10:03:55 +0000
committerJosh Stone <jistone@redhat.com>2024-06-06 11:41:35 -0700
commit4fa46ffbe4744a79e08ba47c6aea5fef89a882ef (patch)
tree70a59cdeaf76ef1c7eebf05cab4c8aef7b5eaf30
parent97e94c19921c6940d5da602384276ee1270268a2 (diff)
downloadrust-4fa46ffbe4744a79e08ba47c6aea5fef89a882ef.tar.gz
rust-4fa46ffbe4744a79e08ba47c6aea5fef89a882ef.zip
Add regression tests
(cherry picked from commit 526090b901cbedcef7e1eec132e217917606a54d)
-rw-r--r--tests/ui/impl-trait/lazy_subtyping_of_opaques.rs59
-rw-r--r--tests/ui/impl-trait/lazy_subtyping_of_opaques.stderr21
-rw-r--r--tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.rs30
-rw-r--r--tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr26
4 files changed, 136 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/lazy_subtyping_of_opaques.rs b/tests/ui/impl-trait/lazy_subtyping_of_opaques.rs
new file mode 100644
index 00000000000..65331894725
--- /dev/null
+++ b/tests/ui/impl-trait/lazy_subtyping_of_opaques.rs
@@ -0,0 +1,59 @@
+//! This test checks that we allow subtyping predicates that contain opaque types.
+//! No hidden types are being constrained in the subtyping predicate, but type and
+//! lifetime variables get subtyped in the generic parameter list of the opaque.
+
+use std::iter;
+
+mod either {
+    pub enum Either<L, R> {
+        Left(L),
+        Right(R),
+    }
+
+    impl<L: Iterator, R: Iterator<Item = L::Item>> Iterator for Either<L, R> {
+        type Item = L::Item;
+        fn next(&mut self) -> Option<Self::Item> {
+            todo!()
+        }
+    }
+    pub use self::Either::{Left, Right};
+}
+
+pub enum BabeConsensusLogRef<'a> {
+    NextEpochData(BabeNextEpochRef<'a>),
+    NextConfigData,
+}
+
+impl<'a> BabeConsensusLogRef<'a> {
+    pub fn scale_encoding(
+        &self,
+    ) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
+        //~^ ERROR is not satisfied
+        //~| ERROR is not satisfied
+        //~| ERROR is not satisfied
+        match self {
+            BabeConsensusLogRef::NextEpochData(digest) => either::Left(either::Left(
+                digest.scale_encoding().map(either::Left).map(either::Left),
+            )),
+            BabeConsensusLogRef::NextConfigData => either::Right(
+                // The Opaque type from ``scale_encoding` gets used opaquely here, while the `R`
+                // generic parameter of `Either` contains type variables that get subtyped and the
+                // opaque type contains lifetime variables that get subtyped.
+                iter::once(either::Right(either::Left([1])))
+                    .chain(std::iter::once([1]).map(either::Right).map(either::Right)),
+            ),
+        }
+    }
+}
+
+pub struct BabeNextEpochRef<'a>(&'a ());
+
+impl<'a> BabeNextEpochRef<'a> {
+    pub fn scale_encoding(
+        &self,
+    ) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
+        std::iter::once([1])
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/lazy_subtyping_of_opaques.stderr b/tests/ui/impl-trait/lazy_subtyping_of_opaques.stderr
new file mode 100644
index 00000000000..2f8c957c2c7
--- /dev/null
+++ b/tests/ui/impl-trait/lazy_subtyping_of_opaques.stderr
@@ -0,0 +1,21 @@
+error[E0277]: the trait bound `Either<Either<Map<Map<impl Iterator<Item = impl AsRef<[u8]> + Clone + '_> + Clone + '_, fn(impl AsRef<[u8]> + Clone + '_) -> Either<impl AsRef<[u8]> + Clone + '_, _> {Either::<impl AsRef<[u8]> + Clone + '_, _>::Left}>, fn(Either<impl AsRef<[u8]> + Clone + '_, _>) -> Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>> {Either::<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>::Left}>, _>, std::iter::Chain<std::iter::Once<Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>>, Map<Map<std::iter::Once<[{integer}; 1]>, fn([{integer}; 1]) -> Either<[{integer}; 1], [{integer}; 1]> {Either::<[{integer}; 1], [{integer}; 1]>::Right}>, fn(Either<[{integer}; 1], [{integer}; 1]>) -> Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>> {Either::<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>::Right}>>>: Clone` is not satisfied
+  --> $DIR/lazy_subtyping_of_opaques.rs:30:10
+   |
+LL |     ) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Either<Either<Map<Map<impl Iterator<Item = impl AsRef<[u8]> + Clone + '_> + Clone + '_, fn(impl AsRef<[u8]> + Clone + '_) -> Either<impl AsRef<[u8]> + Clone + '_, _> {Either::<impl AsRef<[u8]> + Clone + '_, _>::Left}>, fn(Either<impl AsRef<[u8]> + Clone + '_, _>) -> Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>> {Either::<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>::Left}>, _>, std::iter::Chain<std::iter::Once<Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>>, Map<Map<std::iter::Once<[{integer}; 1]>, fn([{integer}; 1]) -> Either<[{integer}; 1], [{integer}; 1]> {Either::<[{integer}; 1], [{integer}; 1]>::Right}>, fn(Either<[{integer}; 1], [{integer}; 1]>) -> Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>> {Either::<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>::Right}>>>`
+
+error[E0277]: the trait bound `Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>: AsRef<[u8]>` is not satisfied
+  --> $DIR/lazy_subtyping_of_opaques.rs:30:31
+   |
+LL |     ) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
+   |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsRef<[u8]>` is not implemented for `Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>`
+
+error[E0277]: the trait bound `Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>: Clone` is not satisfied
+  --> $DIR/lazy_subtyping_of_opaques.rs:30:31
+   |
+LL |     ) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
+   |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.rs b/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.rs
new file mode 100644
index 00000000000..72a90287e37
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.rs
@@ -0,0 +1,30 @@
+#![feature(type_alias_impl_trait)]
+
+//! This test used to ICE rust-lang/rust#124891
+//! because we added an assertion for catching cases where opaque types get
+//! registered during the processing of subtyping predicates.
+
+type Tait = impl FnOnce() -> ();
+
+fn reify_as_tait() -> Thunk<Tait> {
+    Thunk::new(|cont| cont)
+    //~^ ERROR: mismatched types
+    //~| ERROR: mismatched types
+}
+
+struct Thunk<F>(F);
+
+impl<F> Thunk<F> {
+    fn new(f: F)
+    where
+        F: ContFn,
+    {
+        todo!();
+    }
+}
+
+trait ContFn {}
+
+impl<F: FnOnce(Tait) -> ()> ContFn for F {}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr b/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr
new file mode 100644
index 00000000000..5a35dc27446
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr
@@ -0,0 +1,26 @@
+error[E0308]: mismatched types
+  --> $DIR/lazy_subtyping_of_opaques.rs:10:23
+   |
+LL | type Tait = impl FnOnce() -> ();
+   |             ------------------- the found opaque type
+...
+LL |     Thunk::new(|cont| cont)
+   |                       ^^^^ expected `()`, found opaque type
+   |
+   = note: expected unit type `()`
+            found opaque type `Tait`
+
+error[E0308]: mismatched types
+  --> $DIR/lazy_subtyping_of_opaques.rs:10:5
+   |
+LL | fn reify_as_tait() -> Thunk<Tait> {
+   |                       ----------- expected `Thunk<_>` because of return type
+LL |     Thunk::new(|cont| cont)
+   |     ^^^^^^^^^^^^^^^^^^^^^^^ expected `Thunk<_>`, found `()`
+   |
+   = note: expected struct `Thunk<_>`
+           found unit type `()`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.