Skip to content

Commit ac1d0d8

Browse files
committed
fmt, use IndexSet directly instead of UniquePredicates
1 parent e1f408e commit ac1d0d8

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

compiler/rustc_typeck/src/collect.rs

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,8 +1679,9 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
16791679
if tcx.features().const_evaluatable_checked {
16801680
let const_evaluatable = const_evaluatable_predicates_of(tcx, def_id, &result);
16811681
if !const_evaluatable.is_empty() {
1682-
result.predicates =
1683-
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(const_evaluatable));
1682+
result.predicates = tcx
1683+
.arena
1684+
.alloc_from_iter(result.predicates.iter().copied().chain(const_evaluatable));
16841685
}
16851686
}
16861687

@@ -1725,9 +1726,13 @@ pub fn const_evaluatable_predicates_of<'tcx>(
17251726
// We only want unique const evaluatable predicates.
17261727
collector.ct.sort();
17271728
collector.ct.dedup();
1728-
collector.ct.into_iter().map(move |(def_id, subst, span)| {
1729-
(ty::PredicateAtom::ConstEvaluatable(def_id, subst).to_predicate(tcx), span)
1730-
}).collect()
1729+
collector
1730+
.ct
1731+
.into_iter()
1732+
.map(move |(def_id, subst, span)| {
1733+
(ty::PredicateAtom::ConstEvaluatable(def_id, subst).to_predicate(tcx), span)
1734+
})
1735+
.collect()
17311736
}
17321737

17331738
/// Returns a list of all type predicates (explicit and implicit) for the definition with
@@ -1767,29 +1772,6 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
17671772

17681773
debug!("explicit_predicates_of(def_id={:?})", def_id);
17691774

1770-
/// A data structure with unique elements, which preserves order of insertion.
1771-
/// Preserving the order of insertion is important here so as not to break
1772-
/// compile-fail UI tests.
1773-
struct UniquePredicates<'tcx> {
1774-
predicates: FxIndexSet<(ty::Predicate<'tcx>, Span)>,
1775-
}
1776-
1777-
impl<'tcx> UniquePredicates<'tcx> {
1778-
fn new() -> Self {
1779-
UniquePredicates { predicates: FxIndexSet::default() }
1780-
}
1781-
1782-
fn push(&mut self, value: (ty::Predicate<'tcx>, Span)) {
1783-
self.predicates.insert(value);
1784-
}
1785-
1786-
fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter: I) {
1787-
for value in iter {
1788-
self.push(value);
1789-
}
1790-
}
1791-
}
1792-
17931775
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
17941776
let node = tcx.hir().get(hir_id);
17951777

@@ -1802,7 +1784,10 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
18021784

18031785
const NO_GENERICS: &hir::Generics<'_> = &hir::Generics::empty();
18041786

1805-
let mut predicates = UniquePredicates::new();
1787+
// We use an `IndexSet` to preserves order of insertion.
1788+
// Preserving the order of insertion is important here so as not to break
1789+
// compile-fail UI tests.
1790+
let mut predicates: FxIndexSet<(ty::Predicate<'_>, Span)> = FxIndexSet::default();
18061791

18071792
let ast_generics = match node {
18081793
Node::TraitItem(item) => {
@@ -1904,7 +1889,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
19041889
// (see below). Recall that a default impl is not itself an impl, but rather a
19051890
// set of defaults that can be incorporated into another impl.
19061891
if let Some(trait_ref) = is_default_impl_trait {
1907-
predicates.push((
1892+
predicates.insert((
19081893
trait_ref.to_poly_trait_ref().without_const().to_predicate(tcx),
19091894
tcx.def_span(def_id),
19101895
));
@@ -1928,7 +1913,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
19281913
hir::GenericBound::Outlives(lt) => {
19291914
let bound = AstConv::ast_region_to_region(&icx, &lt, None);
19301915
let outlives = ty::Binder::bind(ty::OutlivesPredicate(region, bound));
1931-
predicates.push((outlives.to_predicate(tcx), lt.span));
1916+
predicates.insert((outlives.to_predicate(tcx), lt.span));
19321917
}
19331918
_ => bug!(),
19341919
});
@@ -1983,7 +1968,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
19831968
let span = bound_pred.bounded_ty.span;
19841969
let re_root_empty = tcx.lifetimes.re_root_empty;
19851970
let predicate = ty::OutlivesPredicate(ty, re_root_empty);
1986-
predicates.push((
1971+
predicates.insert((
19871972
ty::PredicateAtom::TypeOutlives(predicate)
19881973
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
19891974
span,
@@ -2027,11 +2012,11 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
20272012

20282013
&hir::GenericBound::Outlives(ref lifetime) => {
20292014
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
2030-
predicates.push((
2015+
predicates.insert((
20312016
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region))
20322017
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
20332018
lifetime.span,
2034-
))
2019+
));
20352020
}
20362021
}
20372022
}
@@ -2076,7 +2061,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
20762061
}))
20772062
}
20782063

2079-
let mut predicates: Vec<_> = predicates.predicates.into_iter().collect();
2064+
let mut predicates: Vec<_> = predicates.into_iter().collect();
20802065

20812066
// Subtle: before we store the predicates into the tcx, we
20822067
// sort them so that predicates like `T: Foo<Item=U>` come

0 commit comments

Comments
 (0)