Perform obligation deduplication to avoid buggy ExistentialMismatch
Fix #59326.
This commit is contained in:
parent
ff4a2533a0
commit
b7f23968cc
2 changed files with 39 additions and 3 deletions
|
@ -617,12 +617,22 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
|
||||||
a: &Self,
|
a: &Self,
|
||||||
b: &Self,
|
b: &Self,
|
||||||
) -> RelateResult<'tcx, Self> {
|
) -> RelateResult<'tcx, Self> {
|
||||||
if a.len() != b.len() {
|
let tcx = relation.tcx();
|
||||||
|
|
||||||
|
// FIXME: this is wasteful, but want to do a perf run to see how slow it is.
|
||||||
|
// We need to perform this deduplication as we sometimes generate duplicate projections
|
||||||
|
// in `a`.
|
||||||
|
let mut a_v: Vec<_> = a.into_iter().collect();
|
||||||
|
let mut b_v: Vec<_> = b.into_iter().collect();
|
||||||
|
a_v.sort_by(|a, b| a.stable_cmp(tcx, b));
|
||||||
|
a_v.dedup();
|
||||||
|
b_v.sort_by(|a, b| a.stable_cmp(tcx, b));
|
||||||
|
b_v.dedup();
|
||||||
|
if a_v.len() != b_v.len() {
|
||||||
return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)));
|
return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let tcx = relation.tcx();
|
let v = a_v.into_iter().zip(b_v.into_iter()).map(|(ep_a, ep_b)| {
|
||||||
let v = a.iter().zip(b.iter()).map(|(ep_a, ep_b)| {
|
|
||||||
use crate::ty::ExistentialPredicate::*;
|
use crate::ty::ExistentialPredicate::*;
|
||||||
match (ep_a, ep_b) {
|
match (ep_a, ep_b) {
|
||||||
(Trait(ref a), Trait(ref b)) => Ok(Trait(relation.relate(a, b)?)),
|
(Trait(ref a), Trait(ref b)) => Ok(Trait(relation.relate(a, b)?)),
|
||||||
|
|
26
src/test/ui/issues/issue-59326.rs
Normal file
26
src/test/ui/issues/issue-59326.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// check-pass
|
||||||
|
trait Service {
|
||||||
|
type S;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Framing {
|
||||||
|
type F;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Framing for () {
|
||||||
|
type F = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
trait HttpService<F: Framing>: Service<S = F::F> {}
|
||||||
|
|
||||||
|
type BoxService = Box<dyn HttpService<(), S = ()>>;
|
||||||
|
|
||||||
|
fn build_server<F: FnOnce() -> BoxService>(_: F) {}
|
||||||
|
|
||||||
|
fn make_server<F: Framing>() -> Box<dyn HttpService<F, S = F::F>> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
build_server(|| make_server())
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue