]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_typeck/src/outlives/explicit.rs
New upstream version 1.56.0~beta.4+dfsg1
[rustc.git] / compiler / rustc_typeck / 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> {
9 map: FxHashMap<DefId, 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
8faf50e0
XL
17 pub fn explicit_predicates_of(
18 &mut self,
dc9dc135 19 tcx: TyCtxt<'tcx>,
8faf50e0
XL
20 def_id: DefId,
21 ) -> &RequiredPredicates<'tcx> {
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
XL
32 match predicate.kind().skip_binder() {
33 ty::PredicateKind::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
e74abb32
XL
34 insert_outlives_predicate(
35 tcx,
36 (*ty).into(),
37 reg,
38 span,
39 &mut required_predicates,
40 )
8faf50e0 41 }
94b46f34 42
5869c6ff 43 ty::PredicateKind::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
8faf50e0
XL
44 insert_outlives_predicate(
45 tcx,
46 (*reg1).into(),
47 reg2,
e74abb32 48 span,
8faf50e0
XL
49 &mut required_predicates,
50 )
51 }
83c7162d 52
5869c6ff
XL
53 ty::PredicateKind::Trait(..)
54 | ty::PredicateKind::Projection(..)
55 | ty::PredicateKind::WellFormed(..)
56 | ty::PredicateKind::ObjectSafe(..)
57 | ty::PredicateKind::ClosureKind(..)
58 | ty::PredicateKind::Subtype(..)
94222f64 59 | ty::PredicateKind::Coerce(..)
5869c6ff
XL
60 | ty::PredicateKind::ConstEvaluatable(..)
61 | ty::PredicateKind::ConstEquate(..)
62 | ty::PredicateKind::TypeWellFormedFromEnv(..) => (),
94b46f34 63 }
83c7162d 64 }
83c7162d 65
8faf50e0
XL
66 required_predicates
67 })
83c7162d 68 }
83c7162d 69}