Skip to content

Commit 5ced845

Browse files
committed
correctly dedup ExistentialPredicates
1 parent 2c69266 commit 5ced845

File tree

5 files changed

+7
-25
lines changed

5 files changed

+7
-25
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,8 @@ impl<'tcx> TyCtxt<'tcx> {
24192419
eps: &[ExistentialPredicate<'tcx>],
24202420
) -> &'tcx List<ExistentialPredicate<'tcx>> {
24212421
assert!(!eps.is_empty());
2422-
assert!(eps.windows(2).all(|w| w[0].stable_cmp(self, &w[1]) != Ordering::Greater));
2422+
// Do not allow duplicate existential predicates.
2423+
assert!(eps.windows(2).all(|w| w[0].stable_cmp(self, &w[1]) == Ordering::Less));
24232424
self._intern_existential_predicates(eps)
24242425
}
24252426

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -598,20 +598,11 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
598598
) -> RelateResult<'tcx, Self> {
599599
let tcx = relation.tcx();
600600

601-
// FIXME: this is wasteful, but want to do a perf run to see how slow it is.
602-
// We need to perform this deduplication as we sometimes generate duplicate projections
603-
// in `a`.
604-
let mut a_v: Vec<_> = a.into_iter().collect();
605-
let mut b_v: Vec<_> = b.into_iter().collect();
606-
a_v.sort_by(|a, b| a.stable_cmp(tcx, b));
607-
a_v.dedup();
608-
b_v.sort_by(|a, b| a.stable_cmp(tcx, b));
609-
b_v.dedup();
610-
if a_v.len() != b_v.len() {
601+
if a.len() != b.len() {
611602
return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)));
612603
}
613604

614-
let v = a_v.into_iter().zip(b_v.into_iter()).map(|(ep_a, ep_b)| {
605+
let v = a.into_iter().zip(b.into_iter()).map(|(ep_a, ep_b)| {
615606
use crate::ty::ExistentialPredicate::*;
616607
match (ep_a, ep_b) {
617608
(Trait(a), Trait(b)) => Ok(Trait(relation.relate(a, b)?)),

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
3535
use rustc_trait_selection::traits::wf::object_region_bounds;
3636

3737
use smallvec::SmallVec;
38+
use std::cmp::Ordering;
3839
use std::collections::BTreeSet;
3940
use std::iter;
4041
use std::slice;
@@ -1192,7 +1193,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11921193
)
11931194
.collect::<SmallVec<[_; 8]>>();
11941195
v.sort_by(|a, b| a.stable_cmp(tcx, b));
1195-
v.dedup();
1196+
v.dedup_by(|a, b| a.stable_cmp(tcx, b) == Ordering::Equal);
11961197
let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter()));
11971198

11981199
// Use explicitly-specified region bound.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
// check-pass
12
#![feature(trait_alias)]
23

34
trait I32Iterator = Iterator<Item = i32>;
45

56
fn main() {
67
let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter();
7-
//~^ ERROR type mismatch
88
}

src/test/ui/associated-types/associated-types-overridden-binding-2.stderr

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)