1 use rustc_data_structures
::fx
::FxHashMap
;
2 use rustc_hir
::def_id
::DefId
;
3 use rustc_middle
::ty
::{self, OutlivesPredicate, TyCtxt}
;
8 pub struct ExplicitPredicatesMap
<'tcx
> {
9 map
: FxHashMap
<DefId
, ty
::EarlyBinder
<RequiredPredicates
<'tcx
>>>,
12 impl<'tcx
> ExplicitPredicatesMap
<'tcx
> {
13 pub fn new() -> ExplicitPredicatesMap
<'tcx
> {
14 ExplicitPredicatesMap { map: FxHashMap::default() }
17 pub(crate) fn explicit_predicates_of(
21 ) -> &ty
::EarlyBinder
<RequiredPredicates
<'tcx
>> {
22 self.map
.entry(def_id
).or_insert_with(|| {
23 let predicates
= if def_id
.is_local() {
24 tcx
.explicit_predicates_of(def_id
)
26 tcx
.predicates_of(def_id
)
28 let mut required_predicates
= RequiredPredicates
::default();
30 // process predicates and convert to `RequiredPredicates` entry, see below
31 for &(predicate
, span
) in predicates
.predicates
{
32 match predicate
.kind().skip_binder() {
33 ty
::PredicateKind
::Clause(ty
::Clause
::TypeOutlives(OutlivesPredicate(
36 ))) => insert_outlives_predicate(
41 &mut required_predicates
,
44 ty
::PredicateKind
::Clause(ty
::Clause
::RegionOutlives(OutlivesPredicate(
47 ))) => insert_outlives_predicate(
52 &mut required_predicates
,
55 ty
::PredicateKind
::Clause(ty
::Clause
::Trait(..))
56 | ty
::PredicateKind
::Clause(ty
::Clause
::Projection(..))
57 | ty
::PredicateKind
::WellFormed(..)
58 | ty
::PredicateKind
::ObjectSafe(..)
59 | ty
::PredicateKind
::ClosureKind(..)
60 | ty
::PredicateKind
::Subtype(..)
61 | ty
::PredicateKind
::Coerce(..)
62 | ty
::PredicateKind
::ConstEvaluatable(..)
63 | ty
::PredicateKind
::ConstEquate(..)
64 | ty
::PredicateKind
::Ambiguous
65 | ty
::PredicateKind
::TypeWellFormedFromEnv(..) => (),
69 ty
::EarlyBinder(required_predicates
)