about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/traits/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_middle/src/traits/util.rs')
-rw-r--r--compiler/rustc_middle/src/traits/util.rs62
1 files changed, 0 insertions, 62 deletions
diff --git a/compiler/rustc_middle/src/traits/util.rs b/compiler/rustc_middle/src/traits/util.rs
deleted file mode 100644
index 7437be7a74c..00000000000
--- a/compiler/rustc_middle/src/traits/util.rs
+++ /dev/null
@@ -1,62 +0,0 @@
-use rustc_data_structures::fx::FxHashSet;
-
-use crate::ty::{Clause, PolyTraitRef, ToPolyTraitRef, TyCtxt, Upcast};
-
-/// Given a [`PolyTraitRef`], get the [`Clause`]s implied by the trait's definition.
-///
-/// This only exists in `rustc_middle` because the more powerful elaborator depends on
-/// `rustc_infer` for elaborating outlives bounds -- this should only be used for pretty
-/// printing.
-pub fn super_predicates_for_pretty_printing<'tcx>(
-    tcx: TyCtxt<'tcx>,
-    trait_ref: PolyTraitRef<'tcx>,
-) -> impl Iterator<Item = Clause<'tcx>> {
-    let clause = trait_ref.upcast(tcx);
-    Elaborator { tcx, visited: FxHashSet::from_iter([clause]), stack: vec![clause] }
-}
-
-/// Like [`super_predicates_for_pretty_printing`], except it only returns traits and filters out
-/// all other [`Clause`]s.
-pub fn supertraits_for_pretty_printing<'tcx>(
-    tcx: TyCtxt<'tcx>,
-    trait_ref: PolyTraitRef<'tcx>,
-) -> impl Iterator<Item = PolyTraitRef<'tcx>> {
-    super_predicates_for_pretty_printing(tcx, trait_ref).filter_map(|clause| {
-        clause.as_trait_clause().map(|trait_clause| trait_clause.to_poly_trait_ref())
-    })
-}
-
-struct Elaborator<'tcx> {
-    tcx: TyCtxt<'tcx>,
-    visited: FxHashSet<Clause<'tcx>>,
-    stack: Vec<Clause<'tcx>>,
-}
-
-impl<'tcx> Elaborator<'tcx> {
-    fn elaborate(&mut self, trait_ref: PolyTraitRef<'tcx>) {
-        let super_predicates =
-            self.tcx.explicit_super_predicates_of(trait_ref.def_id()).predicates.iter().filter_map(
-                |&(pred, _)| {
-                    let clause = pred.instantiate_supertrait(self.tcx, trait_ref);
-                    self.visited.insert(clause).then_some(clause)
-                },
-            );
-
-        self.stack.extend(super_predicates);
-    }
-}
-
-impl<'tcx> Iterator for Elaborator<'tcx> {
-    type Item = Clause<'tcx>;
-
-    fn next(&mut self) -> Option<Clause<'tcx>> {
-        if let Some(clause) = self.stack.pop() {
-            if let Some(trait_clause) = clause.as_trait_clause() {
-                self.elaborate(trait_clause.to_poly_trait_ref());
-            }
-            Some(clause)
-        } else {
-            None
-        }
-    }
-}