Skip to content

Commit

Permalink
Auto merge of #115793 - spastorino:smir-explicit-predicates-of, r=oli…
Browse files Browse the repository at this point in the history
…-obk

Add explicit_predicates_of to SMIR

Adding `explicit_predicates_of` so we can use it from Mir formality.

r? `@oli-obk`
  • Loading branch information
bors committed Sep 13, 2023
2 parents 8e455db + 3678dbc commit 1fe747c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_smir/src/stable_mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down

0 comments on commit 1fe747c

Please sign in to comment.