Skip to content

Commit 1160eec

Browse files
supertrait_def_ids was already implemented in middle
1 parent c9870cf commit 1160eec

File tree

2 files changed

+3
-37
lines changed

2 files changed

+3
-37
lines changed

compiler/rustc_middle/src/ty/context.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2466,8 +2466,9 @@ impl<'tcx> TyCtxt<'tcx> {
24662466

24672467
/// Computes the def-ids of the transitive supertraits of `trait_def_id`. This (intentionally)
24682468
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
2469-
/// to identify which traits may define a given associated type to help avoid cycle errors.
2470-
fn supertrait_def_ids(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
2469+
/// to identify which traits may define a given associated type to help avoid cycle errors,
2470+
/// and to make size estimates for vtable layout computation.
2471+
pub fn supertrait_def_ids(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
24712472
let mut set = FxHashSet::default();
24722473
let mut stack = vec![trait_def_id];
24732474

compiler/rustc_middle/src/ty/vtable.rs

-35
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use std::fmt;
33
use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar};
44
use crate::ty::{self, Instance, PolyTraitRef, Ty, TyCtxt};
55
use rustc_ast::Mutability;
6-
use rustc_data_structures::fx::FxHashSet;
7-
use rustc_hir::def_id::DefId;
86
use rustc_macros::HashStable;
97

108
#[derive(Clone, Copy, PartialEq, HashStable)]
@@ -42,45 +40,12 @@ impl<'tcx> fmt::Debug for VtblEntry<'tcx> {
4240
impl<'tcx> TyCtxt<'tcx> {
4341
pub const COMMON_VTABLE_ENTRIES: &'tcx [VtblEntry<'tcx>] =
4442
&[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-
}
5343
}
5444

5545
pub const COMMON_VTABLE_ENTRIES_DROPINPLACE: usize = 0;
5646
pub const COMMON_VTABLE_ENTRIES_SIZE: usize = 1;
5747
pub const COMMON_VTABLE_ENTRIES_ALIGN: usize = 2;
5848

59-
pub struct SupertraitDefIds<'tcx> {
60-
tcx: TyCtxt<'tcx>,
61-
stack: Vec<DefId>,
62-
visited: FxHashSet<DefId>,
63-
}
64-
65-
impl Iterator for SupertraitDefIds<'_> {
66-
type Item = DefId;
67-
68-
fn next(&mut self) -> Option<DefId> {
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-
8449
// Note that we don't have access to a self type here, this has to be purely based on the trait (and
8550
// supertrait) definitions. That means we can't call into the same vtable_entries code since that
8651
// returns a specific instantiation (e.g., with Vacant slots when bounds aren't satisfied). The goal

0 commit comments

Comments
 (0)