about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_smir/src/rustc_smir/mod.rs38
-rw-r--r--compiler/rustc_smir/src/stable_mir/mod.rs15
-rw-r--r--compiler/rustc_smir/src/stable_mir/ty.rs2
3 files changed, 43 insertions, 12 deletions
diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs
index 1f3e7cb97d1..392dbafcb3e 100644
--- a/compiler/rustc_smir/src/rustc_smir/mod.rs
+++ b/compiler/rustc_smir/src/rustc_smir/mod.rs
@@ -108,6 +108,23 @@ impl<'tcx> Context for Tables<'tcx> {
         let generic_def = self.tcx.generics_of(def_id);
         generic_def.stable(self)
     }
+
+    fn predicates_of(
+        &mut self,
+        trait_def: &stable_mir::ty::TraitDef,
+    ) -> stable_mir::GenericPredicates {
+        let trait_def_id = self.trait_def_id(trait_def);
+        let ty::GenericPredicates { parent, predicates } = self.tcx.predicates_of(trait_def_id);
+        stable_mir::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(),
+        }
+    }
 }
 
 pub struct Tables<'tcx> {
@@ -947,12 +964,12 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
 impl<'tcx> Stable<'tcx> for ty::BoundRegionKind {
     type T = stable_mir::ty::BoundRegionKind;
 
-    fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
+    fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
         use stable_mir::ty::BoundRegionKind;
 
         match self {
             ty::BoundRegionKind::BrAnon(option_span) => {
-                BoundRegionKind::BrAnon(option_span.map(|span| opaque(&span)))
+                BoundRegionKind::BrAnon(option_span.map(|span| span.stable(tables)))
             }
             ty::BoundRegionKind::BrNamed(def_id, symbol) => {
                 BoundRegionKind::BrNamed(rustc_internal::br_named_def(*def_id), symbol.to_string())
@@ -1242,14 +1259,6 @@ impl<'tcx> Stable<'tcx> for ty::Generics {
     }
 }
 
-impl<'tcx> Stable<'tcx> for rustc_span::Span {
-    type T = stable_mir::ty::Span;
-
-    fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
-        opaque(self)
-    }
-}
-
 impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
     type T = stable_mir::ty::GenericParamDefKind;
 
@@ -1456,3 +1465,12 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
         opaque(self)
     }
 }
+
+impl<'tcx> Stable<'tcx> for rustc_span::Span {
+    type T = stable_mir::ty::Span;
+
+    fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
+        // FIXME: add a real implementation of stable spans
+        opaque(self)
+    }
+}
diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs
index 8e38e394b98..360f2195c1c 100644
--- a/compiler/rustc_smir/src/stable_mir/mod.rs
+++ b/compiler/rustc_smir/src/stable_mir/mod.rs
@@ -15,7 +15,9 @@ use std::cell::Cell;
 
 use crate::rustc_smir::Tables;
 
-use self::ty::{GenericDef, Generics, ImplDef, ImplTrait, TraitDecl, TraitDef, Ty, TyKind};
+use self::ty::{
+    GenericDef, Generics, ImplDef, ImplTrait, PredicateKind, Span, TraitDecl, TraitDef, Ty, TyKind,
+};
 
 pub mod mir;
 pub mod ty;
@@ -38,6 +40,12 @@ pub type TraitDecls = Vec<TraitDef>;
 /// A list of impl trait decls.
 pub type ImplTraitDecls = Vec<ImplDef>;
 
+/// A list of predicates.
+pub struct GenericPredicates {
+    pub parent: Option<TraitDef>,
+    pub predicates: Vec<(PredicateKind, Span)>,
+}
+
 /// Holds information about a crate.
 #[derive(Clone, PartialEq, Eq, Debug)]
 pub struct Crate {
@@ -101,6 +109,10 @@ pub fn trait_impl(trait_impl: &ImplDef) -> ImplTrait {
     with(|cx| cx.trait_impl(trait_impl))
 }
 
+pub fn predicates_of(trait_def: &TraitDef) -> GenericPredicates {
+    with(|cx| cx.predicates_of(trait_def))
+}
+
 pub trait Context {
     fn entry_fn(&mut self) -> Option<CrateItem>;
     /// Retrieve all items of the local crate that have a MIR associated with them.
@@ -111,6 +123,7 @@ pub trait Context {
     fn all_trait_impls(&mut self) -> ImplTraitDecls;
     fn trait_impl(&mut self, trait_impl: &ImplDef) -> ImplTrait;
     fn generics_of(&mut self, generic_def: &GenericDef) -> Generics;
+    fn predicates_of(&mut self, trait_def: &TraitDef) -> 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 79389f92a50..5929823b1bb 100644
--- a/compiler/rustc_smir/src/stable_mir/ty.rs
+++ b/compiler/rustc_smir/src/stable_mir/ty.rs
@@ -22,7 +22,7 @@ pub struct Const {
 
 type Ident = Opaque;
 pub(crate) type Region = Opaque;
-pub type Span = Opaque;
+pub(crate) type Span = Opaque;
 
 #[derive(Clone, Debug)]
 pub enum TyKind {