Skip to content

Commit 35bf466

Browse files
committed
Remove super_traits_of query, just leave a helper function
1 parent a6136d8 commit 35bf466

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

Diff for: compiler/rustc_middle/src/query/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,6 @@ rustc_queries! {
436436
desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
437437
}
438438

439-
/// Maps from the `DefId` of a trait to the list of
440-
/// all the ancestors super traits.
441-
query super_traits_of(key: DefId) -> Lrc<FxHashSet<DefId>> {
442-
desc { |tcx| "computing the super traits of `{}`", tcx.def_path_str(key) }
443-
}
444-
445439
/// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
446440
/// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
447441
/// subset of super-predicates that reference traits that define the given associated type.

Diff for: compiler/rustc_middle/src/ty/context.rs

+23
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,29 @@ impl<'tcx> TyCtxt<'tcx> {
20952095
})
20962096
}
20972097

2098+
/// Computes the def-ids of the transitive super-traits of `trait_def_id`. This (intentionally)
2099+
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
2100+
/// to identify which traits may define a given associated type to help avoid cycle errors.
2101+
/// Returns `Lrc<FxHashSet<DefId>>` so that cloning is cheaper.
2102+
fn super_traits_of(self, trait_def_id: DefId) -> Lrc<FxHashSet<DefId>> {
2103+
let mut set = FxHashSet::default();
2104+
let mut stack = vec![trait_def_id];
2105+
while let Some(trait_did) = stack.pop() {
2106+
if !set.insert(trait_did) {
2107+
continue;
2108+
}
2109+
2110+
let generic_predicates = self.super_predicates_of(trait_did);
2111+
for (predicate, _) in generic_predicates.predicates {
2112+
if let ty::PredicateAtom::Trait(data, _) = predicate.skip_binders() {
2113+
stack.push(data.def_id());
2114+
}
2115+
}
2116+
}
2117+
2118+
Lrc::new(set)
2119+
}
2120+
20982121
/// Given a closure signature, returns an equivalent fn signature. Detuples
20992122
/// and so forth -- so e.g., if we have a sig with `Fn<(u32, i32)>` then
21002123
/// you would get a `fn(u32, i32)`.

Diff for: compiler/rustc_typeck/src/collect.rs

-25
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_ast::{MetaItemKind, NestedMetaItem};
2626
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
2727
use rustc_data_structures::captures::Captures;
2828
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
29-
use rustc_data_structures::sync::Lrc;
3029
use rustc_errors::{struct_span_err, Applicability};
3130
use rustc_hir as hir;
3231
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -81,7 +80,6 @@ pub fn provide(providers: &mut Providers) {
8180
projection_ty_from_predicates,
8281
explicit_predicates_of,
8382
super_predicates_of,
84-
super_traits_of,
8583
super_predicates_that_define_assoc_type,
8684
trait_explicit_predicates_and_bounds,
8785
type_param_predicates,
@@ -1116,29 +1114,6 @@ fn super_predicates_that_define_assoc_type(
11161114
}
11171115
}
11181116

1119-
/// Computes the def-ids of the transitive super-traits of `trait_def_id`. This (intentionally)
1120-
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
1121-
/// to identify which traits may define a given associated type to help avoid cycle errors.
1122-
/// Returns `Lrc<FxHashSet<DefId>>` so that cloning is cheaper.
1123-
fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> Lrc<FxHashSet<DefId>> {
1124-
let mut set = FxHashSet::default();
1125-
let mut stack = vec![trait_def_id];
1126-
while let Some(trait_did) = stack.pop() {
1127-
if !set.insert(trait_did) {
1128-
continue;
1129-
}
1130-
1131-
let generic_predicates = tcx.super_predicates_of(trait_did);
1132-
for (predicate, _) in generic_predicates.predicates {
1133-
if let ty::PredicateAtom::Trait(data, _) = predicate.skip_binders() {
1134-
stack.push(data.def_id());
1135-
}
1136-
}
1137-
}
1138-
1139-
Lrc::new(set)
1140-
}
1141-
11421117
fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
11431118
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
11441119
let item = tcx.hir().expect_item(hir_id);

0 commit comments

Comments
 (0)