Add explicit_predicates_of to SMIR

This commit is contained in:
Santiago Pastorino 2023-09-12 12:57:49 -03:00
parent 55e5c9d705
commit 3678dbc382
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
3 changed files with 22 additions and 0 deletions

View File

@ -135,6 +135,23 @@ impl<'tcx> Context for Tables<'tcx> {
.collect(),
}
}
fn explicit_predicates_of(
&mut self,
def_id: stable_mir::DefId,
) -> stable_mir::ty::GenericPredicates {
let def_id = self[def_id];
let ty::GenericPredicates { parent, predicates } = self.tcx.explicit_predicates_of(def_id);
stable_mir::ty::GenericPredicates {
parent: parent.map(|did| self.trait_def(did)),
predicates: predicates
.iter()
.map(|(clause, span)| {
(clause.as_predicate().kind().skip_binder().stable(self), span.stable(self))
})
.collect(),
}
}
}
#[derive(Clone)]

View File

@ -149,6 +149,7 @@ pub trait Context {
fn trait_impl(&mut self, trait_impl: &ImplDef) -> ImplTrait;
fn generics_of(&mut self, def_id: DefId) -> Generics;
fn predicates_of(&mut self, def_id: DefId) -> GenericPredicates;
fn explicit_predicates_of(&mut self, def_id: DefId) -> GenericPredicates;
/// Get information about the local crate.
fn local_crate(&self) -> Crate;
/// Retrieve a list of all external crates.

View File

@ -395,6 +395,10 @@ impl TraitDecl {
pub fn predicates_of(&self) -> GenericPredicates {
with(|cx| cx.predicates_of(self.def_id.0))
}
pub fn explicit_predicates_of(&self) -> GenericPredicates {
with(|cx| cx.explicit_predicates_of(self.def_id.0))
}
}
pub type ImplTrait = EarlyBinder<TraitRef>;