]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
dfeec247
XL
1use rustc_data_structures::fx::FxHashMap;
2use rustc_hir::def_id::DefId;
ba9703b0 3use rustc_middle::ty::{self, OutlivesPredicate, TyCtxt};
83c7162d 4
94b46f34
XL
5use super::utils::*;
6
8faf50e0
XL
7#[derive(Debug)]
8pub struct ExplicitPredicatesMap<'tcx> {
064997fb 9 map: FxHashMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
83c7162d
XL
10}
11
8faf50e0
XL
12impl<'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(..))
5869c6ff
XL
57 | ty::PredicateKind::WellFormed(..)
58 | ty::PredicateKind::ObjectSafe(..)
59 | ty::PredicateKind::ClosureKind(..)
60 | ty::PredicateKind::Subtype(..)
94222f64 61 | ty::PredicateKind::Coerce(..)
5869c6ff
XL
62 | ty::PredicateKind::ConstEvaluatable(..)
63 | ty::PredicateKind::ConstEquate(..)
487cf647 64 | ty::PredicateKind::Ambiguous
5869c6ff 65 | ty::PredicateKind::TypeWellFormedFromEnv(..) => (),
94b46f34 66 }
83c7162d 67 }
83c7162d 68
064997fb 69 ty::EarlyBinder(required_predicates)
8faf50e0 70 })
83c7162d 71 }
83c7162d 72}