]>
Commit | Line | Data |
---|---|---|
dfeec247 XL |
1 | use rustc_data_structures::fx::FxHashMap; |
2 | use rustc_hir::def_id::DefId; | |
ba9703b0 | 3 | use rustc_middle::ty::{self, OutlivesPredicate, TyCtxt}; |
83c7162d | 4 | |
94b46f34 XL |
5 | use super::utils::*; |
6 | ||
8faf50e0 XL |
7 | #[derive(Debug)] |
8 | pub struct ExplicitPredicatesMap<'tcx> { | |
064997fb | 9 | map: FxHashMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>, |
83c7162d XL |
10 | } |
11 | ||
8faf50e0 XL |
12 | impl<'tcx> ExplicitPredicatesMap<'tcx> { |
13 | pub fn new() -> ExplicitPredicatesMap<'tcx> { | |
dfeec247 | 14 | ExplicitPredicatesMap { map: FxHashMap::default() } |
8faf50e0 | 15 | } |
83c7162d | 16 | |
064997fb | 17 | pub(crate) fn explicit_predicates_of( |
8faf50e0 | 18 | &mut self, |
dc9dc135 | 19 | tcx: TyCtxt<'tcx>, |
8faf50e0 | 20 | def_id: DefId, |
064997fb | 21 | ) -> &ty::EarlyBinder<RequiredPredicates<'tcx>> { |
8faf50e0 XL |
22 | self.map.entry(def_id).or_insert_with(|| { |
23 | let predicates = if def_id.is_local() { | |
a1dfa0c6 | 24 | tcx.explicit_predicates_of(def_id) |
8faf50e0 | 25 | } else { |
a1dfa0c6 | 26 | tcx.predicates_of(def_id) |
8faf50e0 XL |
27 | }; |
28 | let mut required_predicates = RequiredPredicates::default(); | |
83c7162d | 29 | |
8faf50e0 | 30 | // process predicates and convert to `RequiredPredicates` entry, see below |
e74abb32 | 31 | for &(predicate, span) in predicates.predicates { |
5869c6ff | 32 | match predicate.kind().skip_binder() { |
487cf647 FG |
33 | ty::PredicateKind::Clause(ty::Clause::TypeOutlives(OutlivesPredicate( |
34 | ty, | |
35 | reg, | |
36 | ))) => insert_outlives_predicate( | |
37 | tcx, | |
38 | ty.into(), | |
39 | reg, | |
40 | span, | |
41 | &mut required_predicates, | |
42 | ), | |
94b46f34 | 43 | |
487cf647 FG |
44 | ty::PredicateKind::Clause(ty::Clause::RegionOutlives(OutlivesPredicate( |
45 | reg1, | |
46 | reg2, | |
47 | ))) => insert_outlives_predicate( | |
48 | tcx, | |
49 | reg1.into(), | |
50 | reg2, | |
51 | span, | |
52 | &mut required_predicates, | |
53 | ), | |
83c7162d | 54 | |
487cf647 FG |
55 | ty::PredicateKind::Clause(ty::Clause::Trait(..)) |
56 | | ty::PredicateKind::Clause(ty::Clause::Projection(..)) | |
9ffffee4 | 57 | | ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) |
5869c6ff | 58 | | ty::PredicateKind::WellFormed(..) |
353b0b11 | 59 | | ty::PredicateKind::AliasRelate(..) |
5869c6ff XL |
60 | | ty::PredicateKind::ObjectSafe(..) |
61 | | ty::PredicateKind::ClosureKind(..) | |
62 | | ty::PredicateKind::Subtype(..) | |
94222f64 | 63 | | ty::PredicateKind::Coerce(..) |
5869c6ff XL |
64 | | ty::PredicateKind::ConstEvaluatable(..) |
65 | | ty::PredicateKind::ConstEquate(..) | |
487cf647 | 66 | | ty::PredicateKind::Ambiguous |
5869c6ff | 67 | | ty::PredicateKind::TypeWellFormedFromEnv(..) => (), |
94b46f34 | 68 | } |
83c7162d | 69 | } |
83c7162d | 70 | |
064997fb | 71 | ty::EarlyBinder(required_predicates) |
8faf50e0 | 72 | }) |
83c7162d | 73 | } |
83c7162d | 74 | } |