Skip to content

Commit 669a823

Browse files
committed
Add regression tests
1 parent 56c135c commit 669a823

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//! This test checks that we allow subtyping predicates that contain opaque types.
2+
//! No hidden types are being constrained in the subtyping predicate, but type and
3+
//! lifetime variables get subtyped in the generic parameter list of the opaque.
4+
5+
use std::iter;
6+
7+
mod either {
8+
pub enum Either<L, R> {
9+
Left(L),
10+
Right(R),
11+
}
12+
13+
impl<L: Iterator, R: Iterator<Item = L::Item>> Iterator for Either<L, R> {
14+
type Item = L::Item;
15+
fn next(&mut self) -> Option<Self::Item> {
16+
todo!()
17+
}
18+
}
19+
pub use self::Either::{Left, Right};
20+
}
21+
22+
pub enum BabeConsensusLogRef<'a> {
23+
NextEpochData(BabeNextEpochRef<'a>),
24+
NextConfigData,
25+
}
26+
27+
impl<'a> BabeConsensusLogRef<'a> {
28+
pub fn scale_encoding(
29+
&self,
30+
) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
31+
//~^ ERROR is not satisfied
32+
//~| ERROR is not satisfied
33+
//~| ERROR is not satisfied
34+
match self {
35+
BabeConsensusLogRef::NextEpochData(digest) => either::Left(either::Left(
36+
digest.scale_encoding().map(either::Left).map(either::Left),
37+
)),
38+
BabeConsensusLogRef::NextConfigData => either::Right(
39+
// The Opaque type from ``scale_encoding` gets used opaquely here, while the `R`
40+
// generic parameter of `Either` contains type variables that get subtyped and the
41+
// opaque type contains lifetime variables that get subtyped.
42+
iter::once(either::Right(either::Left([1])))
43+
.chain(std::iter::once([1]).map(either::Right).map(either::Right)),
44+
),
45+
}
46+
}
47+
}
48+
49+
pub struct BabeNextEpochRef<'a>(&'a ());
50+
51+
impl<'a> BabeNextEpochRef<'a> {
52+
pub fn scale_encoding(
53+
&self,
54+
) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
55+
std::iter::once([1])
56+
}
57+
}
58+
59+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
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
2+
--> $DIR/lazy_subtyping_of_opaques.rs:30:10
3+
|
4+
LL | ) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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}>>>`
6+
7+
error[E0277]: the trait bound `Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>: AsRef<[u8]>` is not satisfied
8+
--> $DIR/lazy_subtyping_of_opaques.rs:30:31
9+
|
10+
LL | ) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `AsRef<[u8]>` is not implemented for `Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>`
12+
13+
error[E0277]: the trait bound `Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>: Clone` is not satisfied
14+
--> $DIR/lazy_subtyping_of_opaques.rs:30:31
15+
|
16+
LL | ) -> impl Iterator<Item = impl AsRef<[u8]> + Clone + 'a> + Clone + 'a {
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Either<Either<impl AsRef<[u8]> + Clone + '_, _>, Either<[{integer}; 1], [{integer}; 1]>>`
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
//! This test used to ICE rust-lang/rust#124891
4+
//! because we added an assertion for catching cases where opaque types get
5+
//! registered during the processing of subtyping predicates.
6+
7+
type Tait = impl FnOnce() -> ();
8+
9+
fn reify_as_tait() -> Thunk<Tait> {
10+
Thunk::new(|cont| cont)
11+
//~^ ERROR: mismatched types
12+
//~| ERROR: mismatched types
13+
}
14+
15+
struct Thunk<F>(F);
16+
17+
impl<F> Thunk<F> {
18+
fn new(f: F)
19+
where
20+
F: ContFn,
21+
{
22+
todo!();
23+
}
24+
}
25+
26+
trait ContFn {}
27+
28+
impl<F: FnOnce(Tait) -> ()> ContFn for F {}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/lazy_subtyping_of_opaques.rs:10:23
3+
|
4+
LL | type Tait = impl FnOnce() -> ();
5+
| ------------------- the found opaque type
6+
...
7+
LL | Thunk::new(|cont| cont)
8+
| ^^^^ expected `()`, found opaque type
9+
|
10+
= note: expected unit type `()`
11+
found opaque type `Tait`
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/lazy_subtyping_of_opaques.rs:10:5
15+
|
16+
LL | fn reify_as_tait() -> Thunk<Tait> {
17+
| ----------- expected `Thunk<_>` because of return type
18+
LL | Thunk::new(|cont| cont)
19+
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `Thunk<_>`, found `()`
20+
|
21+
= note: expected struct `Thunk<_>`
22+
found unit type `()`
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)