Allow constraining opaque types during subtyping in the trait system · rust-lang/rust@ba4510e (original) (raw)
`@@ -2,58 +2,23 @@
`
2
2
`//! No hidden types are being constrained in the subtyping predicate, but type and
`
3
3
`//! lifetime variables get subtyped in the generic parameter list of the opaque.
`
4
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) -> OptionSelf::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])
`
``
5
`+
//@ check-pass
`
``
6
+
``
7
`+
fn foo() -> impl Default + Copy {
`
``
8
`+
if false {
`
``
9
`+
let x = Default::default();
`
``
10
`` +
// add Subtype(?x, ?y)
obligation
``
``
11
`+
let y = x;
`
``
12
+
``
13
`` +
// Make a tuple (?x, ?y)
and equate it with (impl Default, u32)
.
``
``
14
`` +
// For us to try and prove a Subtype(impl Default, u32)
obligation,
``
``
15
`` +
// we have to instantiate both ?x
and ?y
without any
``
``
16
`` +
// select_where_possible
calls inbetween.
``
``
17
`+
let mut tup = &mut (x, y);
`
``
18
`+
let assign_tup = &mut (foo(), 1u32);
`
``
19
`+
tup = assign_tup;
`
56
20
`}
`
``
21
`+
1u32
`
57
22
`}
`
58
23
``
59
24
`fn main() {}
`