From 35bf466a2764abde4c78389c5fc91ca9c4e9ab28 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 25 Nov 2020 12:53:52 -0300 Subject: [PATCH] Remove super_traits_of query, just leave a helper function --- compiler/rustc_middle/src/query/mod.rs | 6 ------ compiler/rustc_middle/src/ty/context.rs | 23 +++++++++++++++++++++++ compiler/rustc_typeck/src/collect.rs | 25 ------------------------- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index aba534ac19f9..b516810205fe 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -436,12 +436,6 @@ rustc_queries! { desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) } } - /// Maps from the `DefId` of a trait to the list of - /// all the ancestors super traits. - query super_traits_of(key: DefId) -> Lrc> { - desc { |tcx| "computing the super traits of `{}`", tcx.def_path_str(key) } - } - /// The `Option` is the name of an associated type. If it is `None`, then this query /// returns the full set of predicates. If `Some`, then the query returns only the /// subset of super-predicates that reference traits that define the given associated type. diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index b2a8b33e4ff5..6a60d65661a7 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2095,6 +2095,29 @@ impl<'tcx> TyCtxt<'tcx> { }) } + /// Computes the def-ids of the transitive super-traits 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. + /// Returns `Lrc>` so that cloning is cheaper. + fn super_traits_of(self, trait_def_id: DefId) -> Lrc> { + let mut set = FxHashSet::default(); + let mut stack = vec![trait_def_id]; + while let Some(trait_did) = stack.pop() { + if !set.insert(trait_did) { + continue; + } + + let generic_predicates = self.super_predicates_of(trait_did); + for (predicate, _) in generic_predicates.predicates { + if let ty::PredicateAtom::Trait(data, _) = predicate.skip_binders() { + stack.push(data.def_id()); + } + } + } + + Lrc::new(set) + } + /// Given a closure signature, returns an equivalent fn signature. Detuples /// and so forth -- so e.g., if we have a sig with `Fn<(u32, i32)>` then /// you would get a `fn(u32, i32)`. diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 316e88b53840..28c4da1a7432 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -26,7 +26,6 @@ use rustc_ast::{MetaItemKind, NestedMetaItem}; use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; -use rustc_data_structures::sync::Lrc; use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; @@ -81,7 +80,6 @@ pub fn provide(providers: &mut Providers) { projection_ty_from_predicates, explicit_predicates_of, super_predicates_of, - super_traits_of, super_predicates_that_define_assoc_type, trait_explicit_predicates_and_bounds, type_param_predicates, @@ -1116,29 +1114,6 @@ fn super_predicates_that_define_assoc_type( } } -/// Computes the def-ids of the transitive super-traits 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. -/// Returns `Lrc>` so that cloning is cheaper. -fn super_traits_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> Lrc> { - let mut set = FxHashSet::default(); - let mut stack = vec![trait_def_id]; - while let Some(trait_did) = stack.pop() { - if !set.insert(trait_did) { - continue; - } - - let generic_predicates = tcx.super_predicates_of(trait_did); - for (predicate, _) in generic_predicates.predicates { - if let ty::PredicateAtom::Trait(data, _) = predicate.skip_binders() { - stack.push(data.def_id()); - } - } - } - - Lrc::new(set) -} - fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef { let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let item = tcx.hir().expect_item(hir_id);