@@ -1679,8 +1679,9 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
1679
1679
if tcx. features ( ) . const_evaluatable_checked {
1680
1680
let const_evaluatable = const_evaluatable_predicates_of ( tcx, def_id, & result) ;
1681
1681
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) ) ;
1684
1685
}
1685
1686
}
1686
1687
@@ -1725,9 +1726,13 @@ pub fn const_evaluatable_predicates_of<'tcx>(
1725
1726
// We only want unique const evaluatable predicates.
1726
1727
collector. ct . sort ( ) ;
1727
1728
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 ( )
1731
1736
}
1732
1737
1733
1738
/// 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
1767
1772
1768
1773
debug ! ( "explicit_predicates_of(def_id={:?})" , def_id) ;
1769
1774
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
-
1793
1775
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id. expect_local ( ) ) ;
1794
1776
let node = tcx. hir ( ) . get ( hir_id) ;
1795
1777
@@ -1802,7 +1784,10 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
1802
1784
1803
1785
const NO_GENERICS : & hir:: Generics < ' _ > = & hir:: Generics :: empty ( ) ;
1804
1786
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 ( ) ;
1806
1791
1807
1792
let ast_generics = match node {
1808
1793
Node :: TraitItem ( item) => {
@@ -1904,7 +1889,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
1904
1889
// (see below). Recall that a default impl is not itself an impl, but rather a
1905
1890
// set of defaults that can be incorporated into another impl.
1906
1891
if let Some ( trait_ref) = is_default_impl_trait {
1907
- predicates. push ( (
1892
+ predicates. insert ( (
1908
1893
trait_ref. to_poly_trait_ref ( ) . without_const ( ) . to_predicate ( tcx) ,
1909
1894
tcx. def_span ( def_id) ,
1910
1895
) ) ;
@@ -1928,7 +1913,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
1928
1913
hir:: GenericBound :: Outlives ( lt) => {
1929
1914
let bound = AstConv :: ast_region_to_region ( & icx, & lt, None ) ;
1930
1915
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 ) ) ;
1932
1917
}
1933
1918
_ => bug ! ( ) ,
1934
1919
} ) ;
@@ -1983,7 +1968,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
1983
1968
let span = bound_pred. bounded_ty . span ;
1984
1969
let re_root_empty = tcx. lifetimes . re_root_empty ;
1985
1970
let predicate = ty:: OutlivesPredicate ( ty, re_root_empty) ;
1986
- predicates. push ( (
1971
+ predicates. insert ( (
1987
1972
ty:: PredicateAtom :: TypeOutlives ( predicate)
1988
1973
. potentially_quantified ( tcx, ty:: PredicateKind :: ForAll ) ,
1989
1974
span,
@@ -2027,11 +2012,11 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
2027
2012
2028
2013
& hir:: GenericBound :: Outlives ( ref lifetime) => {
2029
2014
let region = AstConv :: ast_region_to_region ( & icx, lifetime, None ) ;
2030
- predicates. push ( (
2015
+ predicates. insert ( (
2031
2016
ty:: PredicateAtom :: TypeOutlives ( ty:: OutlivesPredicate ( ty, region) )
2032
2017
. potentially_quantified ( tcx, ty:: PredicateKind :: ForAll ) ,
2033
2018
lifetime. span ,
2034
- ) )
2019
+ ) ) ;
2035
2020
}
2036
2021
}
2037
2022
}
@@ -2076,7 +2061,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
2076
2061
} ) )
2077
2062
}
2078
2063
2079
- let mut predicates: Vec < _ > = predicates. predicates . into_iter ( ) . collect ( ) ;
2064
+ let mut predicates: Vec < _ > = predicates. into_iter ( ) . collect ( ) ;
2080
2065
2081
2066
// Subtle: before we store the predicates into the tcx, we
2082
2067
// sort them so that predicates like `T: Foo<Item=U>` come
0 commit comments