diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 7e533f990fd..b839f083057 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -135,6 +135,23 @@ fn predicates_of(&mut self, def_id: stable_mir::DefId) -> stable_mir::ty::Generi .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)] diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index 508e3aa1291..ef5901482d8 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -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. diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 54cba1263b7..76e7beac571 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -395,6 +395,10 @@ pub fn generics_of(&self) -> Generics { 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;