supertrait_def_ids was already implemented in middle · rust-lang/rust@1160eec (original) (raw)
`@@ -3,8 +3,6 @@ use std::fmt;
`
3
3
`use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar};
`
4
4
`use crate::ty::{self, Instance, PolyTraitRef, Ty, TyCtxt};
`
5
5
`use rustc_ast::Mutability;
`
6
``
`-
use rustc_data_structures::fx::FxHashSet;
`
7
``
`-
use rustc_hir::def_id::DefId;
`
8
6
`use rustc_macros::HashStable;
`
9
7
``
10
8
`#[derive(Clone, Copy, PartialEq, HashStable)]
`
`@@ -42,45 +40,12 @@ impl<'tcx> fmt::Debug for VtblEntry<'tcx> {
`
42
40
`impl<'tcx> TyCtxt<'tcx> {
`
43
41
`pub const COMMON_VTABLE_ENTRIES: &'tcx [VtblEntry<'tcx>] =
`
44
42
`&[VtblEntry::MetadataDropInPlace, VtblEntry::MetadataSize, VtblEntry::MetadataAlign];
`
45
``
-
46
``
`-
pub fn supertrait_def_ids(self, trait_def_id: DefId) -> SupertraitDefIds<'tcx> {
`
47
``
`-
SupertraitDefIds {
`
48
``
`-
tcx: self,
`
49
``
`-
stack: vec![trait_def_id],
`
50
``
`-
visited: Some(trait_def_id).into_iter().collect(),
`
51
``
`-
}
`
52
``
`-
}
`
53
43
`}
`
54
44
``
55
45
`pub const COMMON_VTABLE_ENTRIES_DROPINPLACE: usize = 0;
`
56
46
`pub const COMMON_VTABLE_ENTRIES_SIZE: usize = 1;
`
57
47
`pub const COMMON_VTABLE_ENTRIES_ALIGN: usize = 2;
`
58
48
``
59
``
`-
pub struct SupertraitDefIds<'tcx> {
`
60
``
`-
tcx: TyCtxt<'tcx>,
`
61
``
`-
stack: Vec,
`
62
``
`-
visited: FxHashSet,
`
63
``
`-
}
`
64
``
-
65
``
`-
impl Iterator for SupertraitDefIds<'_> {
`
66
``
`-
type Item = DefId;
`
67
``
-
68
``
`-
fn next(&mut self) -> Option {
`
69
``
`-
let def_id = self.stack.pop()?;
`
70
``
`-
let predicates = self.tcx.explicit_super_predicates_of(def_id);
`
71
``
`-
let visited = &mut self.visited;
`
72
``
`-
self.stack.extend(
`
73
``
`-
predicates
`
74
``
`-
.predicates
`
75
``
`-
.iter()
`
76
``
`-
.filter_map(|(pred, _)| pred.as_trait_clause())
`
77
``
`-
.map(|trait_ref| trait_ref.def_id())
`
78
``
`-
.filter(|&super_def_id| visited.insert(super_def_id)),
`
79
``
`-
);
`
80
``
`-
Some(def_id)
`
81
``
`-
}
`
82
``
`-
}
`
83
``
-
84
49
`// Note that we don't have access to a self type here, this has to be purely based on the trait (and
`
85
50
`// supertrait) definitions. That means we can't call into the same vtable_entries code since that
`
86
51
`// returns a specific instantiation (e.g., with Vacant slots when bounds aren't satisfied). The goal
`