]> git.proxmox.com Git - rustc.git/blob - src/librustc_typeck/outlives/explicit.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / src / librustc_typeck / outlives / explicit.rs
1 use rustc::hir::def_id::DefId;
2 use rustc::ty::{self, OutlivesPredicate, TyCtxt};
3 use crate::util::nodemap::FxHashMap;
4
5 use super::utils::*;
6
7 #[derive(Debug)]
8 pub struct ExplicitPredicatesMap<'tcx> {
9 map: FxHashMap<DefId, RequiredPredicates<'tcx>>,
10 }
11
12 impl<'tcx> ExplicitPredicatesMap<'tcx> {
13 pub fn new() -> ExplicitPredicatesMap<'tcx> {
14 ExplicitPredicatesMap {
15 map: FxHashMap::default(),
16 }
17 }
18
19 pub fn explicit_predicates_of(
20 &mut self,
21 tcx: TyCtxt<'_, 'tcx, 'tcx>,
22 def_id: DefId,
23 ) -> &RequiredPredicates<'tcx> {
24 self.map.entry(def_id).or_insert_with(|| {
25 let predicates = if def_id.is_local() {
26 tcx.explicit_predicates_of(def_id)
27 } else {
28 tcx.predicates_of(def_id)
29 };
30 let mut required_predicates = RequiredPredicates::default();
31
32 // process predicates and convert to `RequiredPredicates` entry, see below
33 for (pred, _) in predicates.predicates.iter() {
34 match pred {
35 ty::Predicate::TypeOutlives(predicate) => {
36 let OutlivesPredicate(ref ty, ref reg) = predicate.skip_binder();
37 insert_outlives_predicate(tcx, (*ty).into(), reg, &mut required_predicates)
38 }
39
40 ty::Predicate::RegionOutlives(predicate) => {
41 let OutlivesPredicate(ref reg1, ref reg2) = predicate.skip_binder();
42 insert_outlives_predicate(
43 tcx,
44 (*reg1).into(),
45 reg2,
46 &mut required_predicates,
47 )
48 }
49
50 ty::Predicate::Trait(..)
51 | ty::Predicate::Projection(..)
52 | ty::Predicate::WellFormed(..)
53 | ty::Predicate::ObjectSafe(..)
54 | ty::Predicate::ClosureKind(..)
55 | ty::Predicate::Subtype(..)
56 | ty::Predicate::ConstEvaluatable(..) => (),
57 }
58 }
59
60 required_predicates
61 })
62 }
63 }