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.
This commit is contained in:
commit
3396a383bb
70 changed files with 281 additions and 404 deletions
|
@ -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 };
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue