2024-02-11 19:50:50 +08:00
|
|
|
use rustc_data_structures::fx::FxIndexMap;
|
2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir::def_id::DefId;
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_middle::ty::{self, OutlivesPredicate, TyCtxt};
|
2017-10-15 01:13:56 -04:00
|
|
|
|
2018-04-18 22:26:21 -04:00
|
|
|
use super::utils::*;
|
|
|
|
|
2018-07-03 00:09:01 -04:00
|
|
|
#[derive(Debug)]
|
2024-08-27 13:14:50 +10:00
|
|
|
pub(crate) struct ExplicitPredicatesMap<'tcx> {
|
2024-05-26 20:03:47 -04:00
|
|
|
map: FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>>>,
|
2017-10-15 01:13:56 -04:00
|
|
|
}
|
|
|
|
|
2018-07-03 00:09:01 -04:00
|
|
|
impl<'tcx> ExplicitPredicatesMap<'tcx> {
|
2024-08-27 13:14:50 +10:00
|
|
|
pub(crate) fn new() -> ExplicitPredicatesMap<'tcx> {
|
2024-02-11 19:50:50 +08:00
|
|
|
ExplicitPredicatesMap { map: FxIndexMap::default() }
|
2018-07-03 00:09:01 -04:00
|
|
|
}
|
2017-10-15 01:13:56 -04:00
|
|
|
|
2022-07-02 18:27:49 -04:00
|
|
|
pub(crate) fn explicit_predicates_of(
|
2018-07-03 00:09:01 -04:00
|
|
|
&mut self,
|
2019-06-14 00:48:52 +03:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2018-07-03 00:09:01 -04:00
|
|
|
def_id: DefId,
|
2024-05-26 20:03:47 -04:00
|
|
|
) -> &ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>> {
|
2018-07-03 00:09:01 -04:00
|
|
|
self.map.entry(def_id).or_insert_with(|| {
|
|
|
|
let predicates = if def_id.is_local() {
|
2018-11-08 17:14:13 +11:00
|
|
|
tcx.explicit_predicates_of(def_id)
|
2018-07-03 00:09:01 -04:00
|
|
|
} else {
|
2018-11-08 17:14:13 +11:00
|
|
|
tcx.predicates_of(def_id)
|
2018-07-03 00:09:01 -04:00
|
|
|
};
|
|
|
|
let mut required_predicates = RequiredPredicates::default();
|
2017-10-15 01:13:56 -04:00
|
|
|
|
2018-07-03 00:09:01 -04:00
|
|
|
// process predicates and convert to `RequiredPredicates` entry, see below
|
2019-10-19 03:45:16 +03:00
|
|
|
for &(predicate, span) in predicates.predicates {
|
2021-01-07 11:20:28 -05:00
|
|
|
match predicate.kind().skip_binder() {
|
2023-06-22 18:17:13 +00:00
|
|
|
ty::ClauseKind::TypeOutlives(OutlivesPredicate(ty, reg)) => {
|
|
|
|
insert_outlives_predicate(
|
|
|
|
tcx,
|
|
|
|
ty.into(),
|
|
|
|
reg,
|
|
|
|
span,
|
|
|
|
&mut required_predicates,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
ty::ClauseKind::RegionOutlives(OutlivesPredicate(reg1, reg2)) => {
|
|
|
|
insert_outlives_predicate(
|
|
|
|
tcx,
|
|
|
|
reg1.into(),
|
|
|
|
reg2,
|
|
|
|
span,
|
|
|
|
&mut required_predicates,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
ty::ClauseKind::Trait(_)
|
|
|
|
| ty::ClauseKind::Projection(_)
|
|
|
|
| ty::ClauseKind::ConstArgHasType(_, _)
|
|
|
|
| ty::ClauseKind::WellFormed(_)
|
2024-10-20 19:49:11 +00:00
|
|
|
| ty::ClauseKind::ConstEvaluatable(_)
|
|
|
|
| ty::ClauseKind::HostEffect(..) => {}
|
2018-04-18 22:26:21 -04:00
|
|
|
}
|
2017-10-15 01:13:56 -04:00
|
|
|
}
|
|
|
|
|
2023-05-29 13:46:10 +02:00
|
|
|
ty::EarlyBinder::bind(required_predicates)
|
2018-07-03 00:09:01 -04:00
|
|
|
})
|
2017-10-15 01:13:56 -04:00
|
|
|
}
|
|
|
|
}
|