rustc_hir_analysis/outlives/
explicit.rs1use rustc_data_structures::fx::FxIndexMap;
2use rustc_hir::def_id::DefId;
3use rustc_middle::ty::{self, OutlivesClause, TyCtxt};
4
5use super::utils::*;
6
7#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ExplicitClausesMap<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ExplicitClausesMap", "map", &&self.map)
}
}Debug)]
8pub(crate) struct ExplicitClausesMap<'tcx> {
9 map: FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredClauses<'tcx>>>,
10}
11
12impl<'tcx> ExplicitClausesMap<'tcx> {
13 pub(crate) fn new() -> ExplicitClausesMap<'tcx> {
14 ExplicitClausesMap { map: FxIndexMap::default() }
15 }
16
17 pub(crate) fn explicit_clauses_of(
18 &mut self,
19 tcx: TyCtxt<'tcx>,
20 def_id: DefId,
21 ) -> &ty::EarlyBinder<'tcx, RequiredClauses<'tcx>> {
22 self.map.entry(def_id).or_insert_with(|| {
23 let gen_clauses = if def_id.is_local() {
24 tcx.explicit_clauses_of(def_id)
25 } else {
26 tcx.clauses_of(def_id)
27 };
28 let mut required_clauses = RequiredClauses::default();
29
30 for &(clause, span) in gen_clauses.clauses {
32 match clause.kind().skip_binder() {
33 ty::ClauseKind::TypeOutlives(OutlivesClause(ty, reg)) => {
34 insert_outlives_clause(tcx, ty.into(), reg, span, &mut required_clauses)
35 }
36
37 ty::ClauseKind::RegionOutlives(OutlivesClause(reg1, reg2)) => {
38 insert_outlives_clause(tcx, reg1.into(), reg2, span, &mut required_clauses)
39 }
40 ty::ClauseKind::Trait(_)
41 | ty::ClauseKind::Projection(_)
42 | ty::ClauseKind::ConstArgHasType(_, _)
43 | ty::ClauseKind::WellFormed(_)
44 | ty::ClauseKind::ConstEvaluatable(_)
45 | ty::ClauseKind::UnstableFeature(_)
46 | ty::ClauseKind::HostEffect(..) => {}
47 }
48 }
49
50 ty::EarlyBinder::bind_iter(required_clauses)
51 })
52 }
53}