]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_hir_analysis/src/outlives/explicit.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / compiler / rustc_hir_analysis / src / outlives / explicit.rs
1 use rustc_data_structures::fx::FxHashMap;
2 use rustc_hir::def_id::DefId;
3 use rustc_middle::ty::{self, OutlivesPredicate, TyCtxt};
4
5 use super::utils::*;
6
7 #[derive(Debug)]
8 pub struct ExplicitPredicatesMap<'tcx> {
9 map: FxHashMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
10 }
11
12 impl<'tcx> ExplicitPredicatesMap<'tcx> {
13 pub fn new() -> ExplicitPredicatesMap<'tcx> {
14 ExplicitPredicatesMap { map: FxHashMap::default() }
15 }
16
17 pub(crate) fn explicit_predicates_of(
18 &mut self,
19 tcx: TyCtxt<'tcx>,
20 def_id: DefId,
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)
25 } else {
26 tcx.predicates_of(def_id)
27 };
28 let mut required_predicates = RequiredPredicates::default();
29
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(
34 ty,
35 reg,
36 ))) => insert_outlives_predicate(
37 tcx,
38 ty.into(),
39 reg,
40 span,
41 &mut required_predicates,
42 ),
43
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 ),
54
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(..) => (),
66 }
67 }
68
69 ty::EarlyBinder(required_predicates)
70 })
71 }
72 }