From 1fb9cad50a8d538bf4903f8c2e6af5c2bd6a3081 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 11 May 2021 14:50:54 +0200 Subject: [PATCH] Use () for analysis. --- compiler/rustc_driver/src/lib.rs | 3 +-- compiler/rustc_driver/src/pretty.rs | 5 ++--- compiler/rustc_interface/src/passes.rs | 6 ++---- compiler/rustc_interface/src/queries.rs | 2 +- compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 6 +++--- compiler/rustc_middle/src/middle/cstore.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 7 +++---- compiler/rustc_middle/src/ty/context.rs | 5 +---- compiler/rustc_typeck/src/check_unused.rs | 4 ++-- 9 files changed, 16 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 18114634209..c9b36dd0c24 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -21,7 +21,6 @@ use rustc_errors::registry::{InvalidErrorCode, Registry}; use rustc_errors::{ErrorReported, PResult}; use rustc_feature::find_gated_cfg; -use rustc_hir::def_id::LOCAL_CRATE; use rustc_interface::util::{self, collect_crate_types, get_builtin_codegen_backend}; use rustc_interface::{interface, Queries}; use rustc_lint::LintStore; @@ -389,7 +388,7 @@ fn run_compiler( } queries.global_ctxt()?.peek_mut().enter(|tcx| { - let result = tcx.analysis(LOCAL_CRATE); + let result = tcx.analysis(()); if sess.opts.debugging_opts.save_analysis { let crate_name = queries.crate_name()?.peek().clone(); sess.time("save_analysis", || { diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index e0c140b143b..370ec053cbb 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -4,7 +4,6 @@ use rustc_ast_pretty::pprust; use rustc_errors::ErrorReported; use rustc_hir as hir; -use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir_pretty as pprust_hir; use rustc_middle::hir::map as hir_map; use rustc_middle::ty::{self, TyCtxt}; @@ -74,7 +73,7 @@ fn call_with_pp_support_hir(ppmode: &PpHirMode, tcx: TyCtxt<'_>, f: F) -> f(&annotation, tcx.hir().krate()) } PpHirMode::Typed => { - abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess); + abort_on_err(tcx.analysis(()), tcx.sess); let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) }; tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate())) @@ -475,7 +474,7 @@ fn print_with_analysis( ppm: PpMode, ofile: Option<&Path>, ) -> Result<(), ErrorReported> { - tcx.analysis(LOCAL_CRATE)?; + tcx.analysis(())?; let out = match ppm { Mir => { diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index aa418e9b003..cb5c82a4705 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -12,7 +12,7 @@ use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel}; use rustc_errors::{ErrorReported, PResult}; use rustc_expand::base::ExtCtxt; -use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; +use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::Crate; use rustc_lint::LintStore; use rustc_metadata::creader::CStore; @@ -809,9 +809,7 @@ pub fn create_global_ctxt<'tcx>( /// Runs the resolution, type-checking, region checking and other /// miscellaneous analysis passes on the crate. -fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { - assert_eq!(cnum, LOCAL_CRATE); - +fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { rustc_passes::hir_id_validator::check_crate(tcx); let sess = tcx.sess; diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index d04ffb78cd5..92d05e48068 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -285,7 +285,7 @@ pub fn ongoing_codegen(&'tcx self) -> Result<&Query>> { self.ongoing_codegen.compute(|| { let outputs = self.prepare_outputs()?; self.global_ctxt()?.peek_mut().enter(|tcx| { - tcx.analysis(LOCAL_CRATE).ok(); + tcx.analysis(()).ok(); // Don't do code generation if there were any errors self.session().compile_status()?; diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 82c8ef0b584..f93ed974aa8 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -361,9 +361,9 @@ pub fn provide(providers: &mut Providers) { assert_eq!(cnum, LOCAL_CRATE); CStore::from_tcx(tcx).has_global_allocator() }, - postorder_cnums: |tcx, cnum| { - assert_eq!(cnum, LOCAL_CRATE); - tcx.arena.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(cnum)) + postorder_cnums: |tcx, ()| { + tcx.arena + .alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE)) }, ..*providers diff --git a/compiler/rustc_middle/src/middle/cstore.rs b/compiler/rustc_middle/src/middle/cstore.rs index 82b9ebcc7ec..d63116e29c8 100644 --- a/compiler/rustc_middle/src/middle/cstore.rs +++ b/compiler/rustc_middle/src/middle/cstore.rs @@ -251,7 +251,7 @@ pub fn used_crates(tcx: TyCtxt<'_>, prefer: LinkagePreference) -> Vec<(CrateNum, Some((cnum, path)) }) .collect::>(); - let mut ordering = tcx.postorder_cnums(LOCAL_CRATE).to_owned(); + let mut ordering = tcx.postorder_cnums(()).to_owned(); ordering.reverse(); libs.sort_by_cached_key(|&(a, _)| ordering.iter().position(|x| *x == a)); libs diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 8b126d5a404..c243192e8b7 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -114,7 +114,7 @@ cache_on_disk_if { key.is_local() } } - query analysis(key: CrateNum) -> Result<(), ErrorReported> { + query analysis(key: ()) -> Result<(), ErrorReported> { eval_always desc { "running analysis passes on this crate" } } @@ -1381,7 +1381,7 @@ eval_always desc { "looking at the source for a crate" } } - query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] { + query postorder_cnums(_: ()) -> &'tcx [CrateNum] { eval_always desc { "generating a postorder list of CrateNums" } } @@ -1394,8 +1394,7 @@ eval_always desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) } } - query maybe_unused_extern_crates(_: CrateNum) - -> &'tcx [(LocalDefId, Span)] { + query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] { eval_always desc { "looking up all possibly unused extern crates" } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index db24be76785..dde5cbadbd9 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2795,10 +2795,7 @@ pub fn provide(providers: &mut ty::query::Providers) { tcx.crate_name }; providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id); - providers.maybe_unused_extern_crates = |tcx, cnum| { - assert_eq!(cnum, LOCAL_CRATE); - &tcx.maybe_unused_extern_crates[..] - }; + providers.maybe_unused_extern_crates = |tcx, ()| &tcx.maybe_unused_extern_crates[..]; providers.names_imported_by_glob_use = |tcx, id| tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default()); diff --git a/compiler/rustc_typeck/src/check_unused.rs b/compiler/rustc_typeck/src/check_unused.rs index e1743a5dfc1..836bed2a156 100644 --- a/compiler/rustc_typeck/src/check_unused.rs +++ b/compiler/rustc_typeck/src/check_unused.rs @@ -1,7 +1,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_middle::ty::TyCtxt; use rustc_session::lint; @@ -77,7 +77,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) { // can always suggest removing (no matter which edition we are // in). let unused_extern_crates: FxHashMap = tcx - .maybe_unused_extern_crates(LOCAL_CRATE) + .maybe_unused_extern_crates(()) .iter() .filter(|&&(def_id, _)| { // The `def_id` here actually was calculated during resolution (at least -- 2.44.0