diff options
| author | bors <bors@rust-lang.org> | 2021-05-17 01:42:03 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-17 01:42:03 +0000 |
| commit | 3396a383bb1d1fdad8ceeb74f16cf08e0bd62a1b (patch) | |
| tree | 912246be6d9298983c099d904ee9260e77695a62 /compiler/rustc_passes/src | |
| parent | a55748ffe94e71f841c7b1d752779b0db138b342 (diff) | |
| parent | 1ebf6d12426152dc1ce76c174ee0ff69b1a4c5b4 (diff) | |
| download | rust-3396a383bb1d1fdad8ceeb74f16cf08e0bd62a1b.tar.gz rust-3396a383bb1d1fdad8ceeb74f16cf08e0bd62a1b.zip | |
Auto merge of #85178 - cjgillot:local-crate, r=oli-obk
Remove CrateNum parameter for queries that only work on local crate The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea. Using `()` as query key in those cases avoids having to worry about the validity of the query key.
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/dead.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/diagnostic_items.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/entry.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/lang_items.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/lib_features.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/reachable.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/stability.rs | 10 |
7 files changed, 23 insertions, 47 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index bd142677cf9..bef56bbc287 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; -use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{Node, PatKind, TyKind}; @@ -480,7 +480,7 @@ fn create_and_seed_worklist<'tcx>( ) .chain( // Seed entry point - tcx.entry_fn(LOCAL_CRATE).and_then(|(def_id, _)| { + tcx.entry_fn(()).and_then(|(def_id, _)| { def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) }), ) @@ -717,7 +717,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { } pub fn check_crate(tcx: TyCtxt<'_>) { - let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); + let access_levels = &tcx.privacy_access_levels(()); let krate = tcx.hir().krate(); let live_symbols = find_live(tcx, access_levels, krate); let mut visitor = DeadVisitor { tcx, live_symbols }; diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index 8dd3700e5b6..f345d45d178 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -16,7 +16,7 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::Session; -use rustc_span::def_id::{DefId, LocalDefId, LOCAL_CRATE}; +use rustc_span::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_span::symbol::{sym, Symbol}; struct DiagnosticItemCollector<'tcx> { @@ -99,7 +99,9 @@ fn extract(sess: &Session, attrs: &[ast::Attribute]) -> Option<Symbol> { } /// Traverse and collect the diagnostic items in the current -fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> { +fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> FxHashMap<Symbol, DefId> { + assert_eq!(cnum, LOCAL_CRATE); + // Initialize the collector. let mut collector = DiagnosticItemCollector::new(tcx); @@ -114,7 +116,7 @@ fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> { } /// Traverse and collect all the diagnostic items in all crates. -fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> { +fn all_diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashMap<Symbol, DefId> { // Initialize the collector. let mut collector = FxHashMap::default(); @@ -129,12 +131,6 @@ fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> { } pub fn provide(providers: &mut Providers) { - providers.diagnostic_items = |tcx, id| { - assert_eq!(id, LOCAL_CRATE); - collect(tcx) - }; - providers.all_diagnostic_items = |tcx, id| { - assert_eq!(id, LOCAL_CRATE); - collect_all(tcx) - }; + providers.diagnostic_items = diagnostic_items; + providers.all_diagnostic_items = all_diagnostic_items; } diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 65cfe986ad4..ca6a7561f3e 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -1,6 +1,6 @@ use rustc_ast::entry::EntryPointType; use rustc_errors::struct_span_err; -use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{ForeignItem, HirId, ImplItem, Item, ItemKind, TraitItem, CRATE_HIR_ID}; use rustc_middle::hir::map::Map; @@ -48,9 +48,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { } } -fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(DefId, EntryFnType)> { - assert_eq!(cnum, LOCAL_CRATE); - +fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> { let any_exe = tcx.sess.crate_types().iter().any(|ty| *ty == CrateType::Executable); if !any_exe { // No need to find a main function. @@ -227,10 +225,6 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) { err.emit(); } -pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(DefId, EntryFnType)> { - tcx.entry_fn(LOCAL_CRATE) -} - pub fn provide(providers: &mut Providers) { *providers = Providers { entry_fn, ..*providers }; } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 7e6bb9779f0..cfc18062d53 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -15,7 +15,7 @@ use rustc_middle::ty::TyCtxt; use rustc_errors::struct_span_err; use rustc_hir as hir; -use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::def_id::DefId; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::lang_items::{extract, ITEM_REFS}; use rustc_hir::{HirId, LangItem, LanguageItems, Target}; @@ -183,7 +183,7 @@ impl LanguageItemCollector<'tcx> { } /// Traverses and collects all the lang items in all crates. -fn collect(tcx: TyCtxt<'_>) -> LanguageItems { +fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems { // Initialize the collector. let mut collector = LanguageItemCollector::new(tcx); @@ -207,8 +207,5 @@ fn collect(tcx: TyCtxt<'_>) -> LanguageItems { } pub fn provide(providers: &mut Providers) { - providers.get_lang_items = |tcx, id| { - assert_eq!(id, LOCAL_CRATE); - collect(tcx) - }; + providers.get_lang_items = get_lang_items; } diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 3dfe317a4bd..363a6417f99 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -6,7 +6,6 @@ use rustc_ast::{Attribute, MetaItem, MetaItemKind}; use rustc_errors::struct_span_err; -use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_middle::hir::map::Map; use rustc_middle::middle::lib_features::LibFeatures; @@ -127,7 +126,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> { } } -fn collect(tcx: TyCtxt<'_>) -> LibFeatures { +fn get_lib_features(tcx: TyCtxt<'_>, (): ()) -> LibFeatures { let mut collector = LibFeatureCollector::new(tcx); let krate = tcx.hir().krate(); for attr in krate.non_exported_macro_attrs { @@ -138,8 +137,5 @@ fn collect(tcx: TyCtxt<'_>) -> LibFeatures { } pub fn provide(providers: &mut Providers) { - providers.get_lib_features = |tcx, id| { - assert_eq!(id, LOCAL_CRATE); - collect(tcx) - }; + providers.get_lib_features = get_lib_features; } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index ec47f597257..0b3227abb5f 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -8,8 +8,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::LOCAL_CRATE; -use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::Node; @@ -385,10 +384,8 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx } } -fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> FxHashSet<LocalDefId> { - debug_assert!(crate_num == LOCAL_CRATE); - - let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); +fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> { + let access_levels = &tcx.privacy_access_levels(()); let any_library = tcx.sess.crate_types().iter().any(|ty| { diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 6b1813fba76..f41e0e03706 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -629,7 +629,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { // stable (assuming they have not inherited instability from their parent). } -fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> { +fn stability_index(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> { let is_staged_api = tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api; let mut staged_api = FxHashMap::default(); @@ -704,11 +704,7 @@ fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { check_mod_unstable_api_usage, ..*providers }; - providers.stability_index = |tcx, cnum| { - assert_eq!(cnum, LOCAL_CRATE); - new_index(tcx) - }; + *providers = Providers { check_mod_unstable_api_usage, stability_index, ..*providers }; } struct Checker<'tcx> { @@ -880,7 +876,7 @@ impl Visitor<'tcx> for CheckTraitImplStable<'tcx> { /// were expected to be library features), and the list of features used from /// libraries, identify activated features that don't exist and error about them. pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { - let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); + let access_levels = &tcx.privacy_access_levels(()); if tcx.stability().staged_api[&LOCAL_CRATE] { let krate = tcx.hir().krate(); |
