]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_typeck/src/outlives/explicit.rs
Rustdoc render public underscore_imports as Re-exports
[rust.git] / compiler / rustc_typeck / 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, RequiredPredicates<'tcx>>,
10 }
11
12 impl<'tcx> ExplicitPredicatesMap<'tcx> {
13     pub fn new() -> ExplicitPredicatesMap<'tcx> {
14         ExplicitPredicatesMap { map: FxHashMap::default() }
15     }
16
17     pub fn explicit_predicates_of(
18         &mut self,
19         tcx: TyCtxt<'tcx>,
20         def_id: DefId,
21     ) -> &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.skip_binders() {
33                     ty::PredicateAtom::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
34                         insert_outlives_predicate(
35                             tcx,
36                             (*ty).into(),
37                             reg,
38                             span,
39                             &mut required_predicates,
40                         )
41                     }
42
43                     ty::PredicateAtom::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
44                         insert_outlives_predicate(
45                             tcx,
46                             (*reg1).into(),
47                             reg2,
48                             span,
49                             &mut required_predicates,
50                         )
51                     }
52
53                     ty::PredicateAtom::Trait(..)
54                     | ty::PredicateAtom::Projection(..)
55                     | ty::PredicateAtom::WellFormed(..)
56                     | ty::PredicateAtom::ObjectSafe(..)
57                     | ty::PredicateAtom::ClosureKind(..)
58                     | ty::PredicateAtom::Subtype(..)
59                     | ty::PredicateAtom::ConstEvaluatable(..)
60                     | ty::PredicateAtom::ConstEquate(..)
61                     | ty::PredicateAtom::TypeWellFormedFromEnv(..) => (),
62                 }
63             }
64
65             required_predicates
66         })
67     }
68 }