From 4e8d4bdf4b5f185a6096c29147dff7d2d3daa7d7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 11 May 2021 14:22:02 +0200 Subject: [PATCH] Use () for all_traits. --- compiler/rustc_middle/src/query/mod.rs | 2 +- .../src/traits/error_reporting/mod.rs | 4 ++-- compiler/rustc_typeck/src/check/method/suggest.rs | 13 +++++-------- src/librustdoc/clean/blanket_impl.rs | 3 +-- src/librustdoc/core.rs | 4 ++-- src/librustdoc/passes/collect_trait_impls.rs | 4 ++-- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 1165199aecc..1754ab84a55 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1420,7 +1420,7 @@ /// A vector of every trait accessible in the whole crate /// (i.e., including those from subcrates). This is used only for /// error reporting. - query all_traits(_: CrateNum) -> &'tcx [DefId] { + query all_traits(_: ()) -> &'tcx [DefId] { desc { "fetching all foreign and local traits" } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index da5a1af7f77..db396356d67 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; use rustc_hir as hir; -use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_hir::Node; use rustc_middle::mir::abstract_const::NotConstEvaluatable; @@ -1427,7 +1427,7 @@ fn note_version_mismatch( self.tcx.find_map_relevant_impl(trait_def_id, trait_ref.skip_binder().self_ty(), Some) }; let required_trait_path = self.tcx.def_path_str(trait_ref.def_id()); - let all_traits = self.tcx.all_traits(LOCAL_CRATE); + let all_traits = self.tcx.all_traits(()); let traits_with_same_path: std::collections::BTreeSet<_> = all_traits .iter() .filter(|trait_def_id| **trait_def_id != trait_ref.def_id()) diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index b2e4e7a981d..2320a29e6d8 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -6,7 +6,7 @@ use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace, Res}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; use rustc_hir::intravisit; use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, Node, QPath}; @@ -1440,11 +1440,11 @@ fn cmp(&self, other: &TraitInfo) -> Ordering { /// Retrieves all traits in this crate and any dependent crates. pub fn all_traits(tcx: TyCtxt<'_>) -> Vec { - tcx.all_traits(LOCAL_CRATE).iter().map(|&def_id| TraitInfo { def_id }).collect() + tcx.all_traits(()).iter().map(|&def_id| TraitInfo { def_id }).collect() } /// Computes all traits in this crate and any dependent crates. -fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec { +fn compute_all_traits(tcx: TyCtxt<'_>, (): ()) -> &[DefId] { use hir::itemlikevisit; let mut traits = vec![]; @@ -1503,14 +1503,11 @@ fn handle_external_res( handle_external_res(tcx, &mut traits, &mut external_mods, Res::Def(DefKind::Mod, def_id)); } - traits + tcx.arena.alloc_from_iter(traits) } pub fn provide(providers: &mut ty::query::Providers) { - providers.all_traits = |tcx, cnum| { - assert_eq!(cnum, LOCAL_CRATE); - &tcx.arena.alloc(compute_all_traits(tcx))[..] - } + providers.all_traits = compute_all_traits; } struct UsePlacementFinder<'tcx> { diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 68856f82fe9..fd4274863ef 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -1,6 +1,5 @@ use crate::rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_hir as hir; -use rustc_hir::def_id::LOCAL_CRATE; use rustc_infer::infer::{InferOk, TyCtxtInferExt}; use rustc_infer::traits; use rustc_middle::ty::subst::Subst; @@ -20,7 +19,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { debug!("get_blanket_impls({:?})", ty); let mut impls = Vec::new(); - for &trait_def_id in self.cx.tcx.all_traits(LOCAL_CRATE).iter() { + for &trait_def_id in self.cx.tcx.all_traits(()).iter() { if !self.cx.cache.access_levels.is_public(trait_def_id) || self.cx.generated_synthetics.get(&(ty, trait_def_id)).is_some() { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 0f8750b0825..f7980c66c32 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -6,7 +6,7 @@ use rustc_errors::json::JsonEmitter; use rustc_feature::UnstableFeatures; use rustc_hir::def::Res; -use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::HirId; use rustc_hir::{ intravisit::{self, NestedVisitorMap, Visitor}, @@ -371,7 +371,7 @@ impl<'tcx> DocContext<'tcx> { impl_trait_bounds: Default::default(), generated_synthetics: Default::default(), auto_traits: tcx - .all_traits(LOCAL_CRATE) + .all_traits(()) .iter() .cloned() .filter(|trait_def_id| tcx.trait_is_auto(*trait_def_id)) diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 90b797da249..564408768f7 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -4,7 +4,7 @@ use crate::fold::DocFolder; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::def_id::DefId; use rustc_middle::ty::DefIdTree; use rustc_span::symbol::sym; @@ -56,7 +56,7 @@ // `tcx.crates()` doesn't include the local crate, and `tcx.all_trait_implementations` // doesn't work with it anyway, so pull them from the HIR map instead let mut extra_attrs = Vec::new(); - for &trait_did in cx.tcx.all_traits(LOCAL_CRATE).iter() { + for &trait_did in cx.tcx.all_traits(()).iter() { for &impl_did in cx.tcx.hir().trait_impls(trait_did) { let impl_did = impl_did.to_def_id(); cx.tcx.sess.prof.generic_activity("build_local_trait_impl").run(|| {