supertrait_def_ids was already implemented in middle
This commit is contained in:
parent
c9870cfa4b
commit
1160eecba5
@ -2466,8 +2466,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
/// Computes the def-ids of the transitive supertraits of `trait_def_id`. This (intentionally)
|
||||
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
|
||||
/// to identify which traits may define a given associated type to help avoid cycle errors.
|
||||
fn supertrait_def_ids(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
|
||||
/// to identify which traits may define a given associated type to help avoid cycle errors,
|
||||
/// and to make size estimates for vtable layout computation.
|
||||
pub fn supertrait_def_ids(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
|
||||
let mut set = FxHashSet::default();
|
||||
let mut stack = vec![trait_def_id];
|
||||
|
||||
|
@ -3,8 +3,6 @@ use std::fmt;
|
||||
use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar};
|
||||
use crate::ty::{self, Instance, PolyTraitRef, Ty, TyCtxt};
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_macros::HashStable;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, HashStable)]
|
||||
@ -42,45 +40,12 @@ impl<'tcx> fmt::Debug for VtblEntry<'tcx> {
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
pub const COMMON_VTABLE_ENTRIES: &'tcx [VtblEntry<'tcx>] =
|
||||
&[VtblEntry::MetadataDropInPlace, VtblEntry::MetadataSize, VtblEntry::MetadataAlign];
|
||||
|
||||
pub fn supertrait_def_ids(self, trait_def_id: DefId) -> SupertraitDefIds<'tcx> {
|
||||
SupertraitDefIds {
|
||||
tcx: self,
|
||||
stack: vec![trait_def_id],
|
||||
visited: Some(trait_def_id).into_iter().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const COMMON_VTABLE_ENTRIES_DROPINPLACE: usize = 0;
|
||||
pub const COMMON_VTABLE_ENTRIES_SIZE: usize = 1;
|
||||
pub const COMMON_VTABLE_ENTRIES_ALIGN: usize = 2;
|
||||
|
||||
pub struct SupertraitDefIds<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
stack: Vec<DefId>,
|
||||
visited: FxHashSet<DefId>,
|
||||
}
|
||||
|
||||
impl Iterator for SupertraitDefIds<'_> {
|
||||
type Item = DefId;
|
||||
|
||||
fn next(&mut self) -> Option<DefId> {
|
||||
let def_id = self.stack.pop()?;
|
||||
let predicates = self.tcx.explicit_super_predicates_of(def_id);
|
||||
let visited = &mut self.visited;
|
||||
self.stack.extend(
|
||||
predicates
|
||||
.predicates
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| pred.as_trait_clause())
|
||||
.map(|trait_ref| trait_ref.def_id())
|
||||
.filter(|&super_def_id| visited.insert(super_def_id)),
|
||||
);
|
||||
Some(def_id)
|
||||
}
|
||||
}
|
||||
|
||||
// Note that we don't have access to a self type here, this has to be purely based on the trait (and
|
||||
// supertrait) definitions. That means we can't call into the same vtable_entries code since that
|
||||
// returns a specific instantiation (e.g., with Vacant slots when bounds aren't satisfied). The goal
|
||||
|
Loading…
x
Reference in New Issue
Block a user