Skip to content

Commit 1a165ec

Browse files
authored
Rollup merge of #125489 - oli-obk:revert_stuff_2, r=compiler-errors
Revert problematic opaque type change fixes #124891 fixes #125192 reverts #123979
2 parents 54a2bd8 + 526090b commit 1a165ec

File tree

6 files changed

+138
-37
lines changed

6 files changed

+138
-37
lines changed

compiler/rustc_infer/src/infer/mod.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -957,27 +957,14 @@ impl<'tcx> InferCtxt<'tcx> {
957957
(&ty::Infer(ty::TyVar(a_vid)), &ty::Infer(ty::TyVar(b_vid))) => {
958958
return Err((a_vid, b_vid));
959959
}
960-
// We don't silently want to constrain hidden types here, so we assert that either one side is
961-
// an infer var, so it'll get constrained to whatever the other side is, or there are no opaque
962-
// types involved.
963-
// We don't expect this to actually get hit, but if it does, we now at least know how to write
964-
// a test for it.
965-
(_, ty::Infer(ty::TyVar(_))) => {}
966-
(ty::Infer(ty::TyVar(_)), _) => {}
967-
_ if r_a != r_b && (r_a, r_b).has_opaque_types() => {
968-
span_bug!(
969-
cause.span(),
970-
"opaque types got hidden types registered from within subtype predicate: {r_a:?} vs {r_b:?}"
971-
)
972-
}
973960
_ => {}
974961
}
975962

976963
self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
977964
if a_is_expected {
978-
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::Yes, a, b))
965+
Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::No, a, b))
979966
} else {
980-
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::Yes, b, a))
967+
Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::No, b, a))
981968
}
982969
})
983970
}

tests/crashes/124891.rs

-22
This file was deleted.
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)