1
Fork 0

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:
bors 2021-05-17 01:42:03 +00:00
commit 3396a383bb
70 changed files with 281 additions and 404 deletions

View file

@ -13,7 +13,7 @@ pub(crate) fn codegen(
module: &mut impl Module, module: &mut impl Module,
unwind_context: &mut UnwindContext, unwind_context: &mut UnwindContext,
) -> bool { ) -> bool {
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic) list.iter().any(|&linkage| linkage == Linkage::Dynamic)
}); });

View file

@ -42,7 +42,7 @@ fn emit_module(
unwind_context.emit(&mut product); unwind_context.emit(&mut product);
let tmp_file = tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(&name)); let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&name));
let obj = product.object.write().unwrap(); let obj = product.object.write().unwrap();
if let Err(err) = std::fs::write(&tmp_file, obj) { if let Err(err) = std::fs::write(&tmp_file, obj) {
tcx.sess.fatal(&format!("error writing object file: {}", err)); tcx.sess.fatal(&format!("error writing object file: {}", err));
@ -74,7 +74,7 @@ fn reuse_workproduct_for_cgu(
let work_product = cgu.work_product(tcx); let work_product = cgu.work_product(tcx);
if let Some(saved_file) = &work_product.saved_file { if let Some(saved_file) = &work_product.saved_file {
let obj_out = tcx let obj_out = tcx
.output_filenames(LOCAL_CRATE) .output_filenames(())
.temp_path(OutputType::Object, Some(&cgu.name().as_str())); .temp_path(OutputType::Object, Some(&cgu.name().as_str()));
object = Some(obj_out.clone()); object = Some(obj_out.clone());
let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file); let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
@ -190,7 +190,7 @@ pub(crate) fn run_aot(
let mut work_products = FxHashMap::default(); let mut work_products = FxHashMap::default();
let cgus = if tcx.sess.opts.output_types.should_codegen() { let cgus = if tcx.sess.opts.output_types.should_codegen() {
tcx.collect_and_partition_mono_items(LOCAL_CRATE).1 tcx.collect_and_partition_mono_items(()).1
} else { } else {
// If only `--emit metadata` is used, we shouldn't perform any codegen. // If only `--emit metadata` is used, we shouldn't perform any codegen.
// Also `tcx.collect_and_partition_mono_items` may panic in that case. // Also `tcx.collect_and_partition_mono_items` may panic in that case.
@ -276,7 +276,7 @@ pub(crate) fn run_aot(
.to_string(); .to_string();
let tmp_file = tcx let tmp_file = tcx
.output_filenames(LOCAL_CRATE) .output_filenames(())
.temp_path(OutputType::Metadata, Some(&metadata_cgu_name)); .temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
let obj = crate::backend::with_object(tcx.sess, &metadata_cgu_name, |object| { let obj = crate::backend::with_object(tcx.sess, &metadata_cgu_name, |object| {
@ -353,7 +353,7 @@ fn codegen_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &str) {
.join("\n"); .join("\n");
let output_object_file = let output_object_file =
tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(cgu_name)); tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu_name));
// Assemble `global_asm` // Assemble `global_asm`
let global_asm_object_file = add_file_stem_postfix(output_object_file.clone(), ".asm"); let global_asm_object_file = add_file_stem_postfix(output_object_file.clone(), ".asm");

View file

@ -8,7 +8,6 @@ use std::os::raw::{c_char, c_int};
use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
use rustc_codegen_ssa::CrateInfo; use rustc_codegen_ssa::CrateInfo;
use rustc_middle::mir::mono::MonoItem; use rustc_middle::mir::mono::MonoItem;
use rustc_session::config::EntryFnType;
use cranelift_jit::{JITBuilder, JITModule}; use cranelift_jit::{JITBuilder, JITModule};
@ -66,7 +65,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
matches!(backend_config.codegen_mode, CodegenMode::JitLazy), matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
); );
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); let (_, cgus) = tcx.collect_and_partition_mono_items(());
let mono_items = cgus let mono_items = cgus
.iter() .iter()
.map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter()) .map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter())
@ -179,7 +178,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
let mut dylib_paths = Vec::new(); let mut dylib_paths = Vec::new();
let crate_info = CrateInfo::new(tcx); let crate_info = CrateInfo::new(tcx);
let formats = tcx.dependency_formats(LOCAL_CRATE); let formats = tcx.dependency_formats(());
let data = &formats let data = &formats
.iter() .iter()
.find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable) .find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable)

View file

@ -15,7 +15,7 @@ pub(crate) fn maybe_create_entry_wrapper(
unwind_context: &mut UnwindContext, unwind_context: &mut UnwindContext,
is_jit: bool, is_jit: bool,
) { ) {
let (main_def_id, is_main_fn) = match tcx.entry_fn(LOCAL_CRATE) { let (main_def_id, is_main_fn) = match tcx.entry_fn(()) {
Some((def_id, entry_ty)) => ( Some((def_id, entry_ty)) => (
def_id, def_id,
match entry_ty { match entry_ty {

View file

@ -214,7 +214,7 @@ pub(crate) fn write_ir_file(
return; return;
} }
let clif_output_dir = tcx.output_filenames(LOCAL_CRATE).with_extension("clif"); let clif_output_dir = tcx.output_filenames(()).with_extension("clif");
match std::fs::create_dir(&clif_output_dir) { match std::fs::create_dir(&clif_output_dir) {
Ok(()) => {} Ok(()) => {}

View file

@ -20,7 +20,6 @@ use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
use rustc_data_structures::small_c_str::SmallCStr; use rustc_data_structures::small_c_str::SmallCStr;
use rustc_errors::{FatalError, Handler, Level}; use rustc_errors::{FatalError, Handler, Level};
use rustc_fs_util::{link_or_copy, path_to_c_string}; use rustc_fs_util::{link_or_copy, path_to_c_string};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::config::{self, Lto, OutputType, Passes, SwitchWithOptPath}; use rustc_session::config::{self, Lto, OutputType, Passes, SwitchWithOptPath};
@ -92,13 +91,12 @@ pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm:
pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine { pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine {
let split_dwarf_file = if tcx.sess.target_can_use_split_dwarf() { let split_dwarf_file = if tcx.sess.target_can_use_split_dwarf() {
tcx.output_filenames(LOCAL_CRATE) tcx.output_filenames(()).split_dwarf_path(tcx.sess.split_debuginfo(), Some(mod_name))
.split_dwarf_path(tcx.sess.split_debuginfo(), Some(mod_name))
} else { } else {
None None
}; };
let config = TargetMachineFactoryConfig { split_dwarf_file }; let config = TargetMachineFactoryConfig { split_dwarf_file };
target_machine_factory(&tcx.sess, tcx.backend_optimization_level(LOCAL_CRATE))(config) target_machine_factory(&tcx.sess, tcx.backend_optimization_level(()))(config)
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise()) .unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise())
} }

View file

@ -6,7 +6,7 @@ use llvm::coverageinfo::CounterMappingRegion;
use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression}; use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression};
use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods}; use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_hir::def_id::{DefId, DefIdSet, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, DefIdSet};
use rustc_llvm::RustString; use rustc_llvm::RustString;
use rustc_middle::mir::coverage::CodeRegion; use rustc_middle::mir::coverage::CodeRegion;
use rustc_span::Symbol; use rustc_span::Symbol;
@ -265,7 +265,7 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics(); let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();
let all_def_ids: DefIdSet = tcx let all_def_ids: DefIdSet = tcx
.mir_keys(LOCAL_CRATE) .mir_keys(())
.iter() .iter()
.filter_map(|local_def_id| { .filter_map(|local_def_id| {
let def_id = local_def_id.to_def_id(); let def_id = local_def_id.to_def_id();
@ -276,7 +276,7 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
}) })
.collect(); .collect();
let codegenned_def_ids = tcx.codegened_and_inlined_items(LOCAL_CRATE); let codegenned_def_ids = tcx.codegened_and_inlined_items(());
let mut unused_def_ids_by_file: FxHashMap<Symbol, Vec<DefId>> = FxHashMap::default(); let mut unused_def_ids_by_file: FxHashMap<Symbol, Vec<DefId>> = FxHashMap::default();
for &non_codegenned_def_id in all_def_ids.difference(codegenned_def_ids) { for &non_codegenned_def_id in all_def_ids.difference(codegenned_def_ids) {

View file

@ -995,9 +995,10 @@ pub fn compile_unit_metadata(
let name_in_debuginfo = name_in_debuginfo.to_string_lossy(); let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
let work_dir = tcx.sess.working_dir.to_string_lossy(false); let work_dir = tcx.sess.working_dir.to_string_lossy(false);
let flags = "\0"; let flags = "\0";
let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory; let output_filenames = tcx.output_filenames(());
let out_dir = &output_filenames.out_directory;
let split_name = if tcx.sess.target_can_use_split_dwarf() { let split_name = if tcx.sess.target_can_use_split_dwarf() {
tcx.output_filenames(LOCAL_CRATE) output_filenames
.split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name)) .split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
.map(|f| out_dir.join(f)) .map(|f| out_dir.join(f))
} else { } else {
@ -1058,15 +1059,12 @@ pub fn compile_unit_metadata(
if tcx.sess.opts.debugging_opts.profile { if tcx.sess.opts.debugging_opts.profile {
let cu_desc_metadata = let cu_desc_metadata =
llvm::LLVMRustMetadataAsValue(debug_context.llcontext, unit_metadata); llvm::LLVMRustMetadataAsValue(debug_context.llcontext, unit_metadata);
let default_gcda_path = &tcx.output_filenames(LOCAL_CRATE).with_extension("gcda"); let default_gcda_path = &output_filenames.with_extension("gcda");
let gcda_path = let gcda_path =
tcx.sess.opts.debugging_opts.profile_emit.as_ref().unwrap_or(default_gcda_path); tcx.sess.opts.debugging_opts.profile_emit.as_ref().unwrap_or(default_gcda_path);
let gcov_cu_info = [ let gcov_cu_info = [
path_to_mdstring( path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")),
debug_context.llcontext,
&tcx.output_filenames(LOCAL_CRATE).with_extension("gcno"),
),
path_to_mdstring(debug_context.llcontext, &gcda_path), path_to_mdstring(debug_context.llcontext, &gcda_path),
cu_desc_metadata, cu_desc_metadata,
]; ];

View file

@ -23,7 +23,7 @@ use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, Variab
use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::traits::*;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, DefIdMap};
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::layout::HasTyCtxt;
@ -343,7 +343,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
if self.sess().opts.optimize != config::OptLevel::No { if self.sess().opts.optimize != config::OptLevel::No {
spflags |= DISPFlags::SPFlagOptimized; spflags |= DISPFlags::SPFlagOptimized;
} }
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) { if let Some((id, _)) = self.tcx.entry_fn(()) {
if id == def_id { if id == def_id {
spflags |= DISPFlags::SPFlagMainSubprogram; spflags |= DISPFlags::SPFlagMainSubprogram;
} }

View file

@ -1303,7 +1303,7 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
} }
} }
let formats = tcx.dependency_formats(LOCAL_CRATE); let formats = tcx.dependency_formats(());
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap(); let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
for (index, dep_format) in deps.iter().enumerate() { for (index, dep_format) in deps.iter().enumerate() {

View file

@ -4,7 +4,7 @@ use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::Node; use rustc_hir::Node;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@ -60,7 +60,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE); tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
let mut reachable_non_generics: DefIdMap<_> = tcx let mut reachable_non_generics: DefIdMap<_> = tcx
.reachable_set(LOCAL_CRATE) .reachable_set(())
.iter() .iter()
.filter_map(|&def_id| { .filter_map(|&def_id| {
// We want to ignore some FFI functions that are not exposed from // We want to ignore some FFI functions that are not exposed from
@ -133,12 +133,12 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
}) })
.collect(); .collect();
if let Some(id) = tcx.proc_macro_decls_static(LOCAL_CRATE) { if let Some(id) = tcx.proc_macro_decls_static(()) {
reachable_non_generics.insert(id, SymbolExportLevel::C); reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
} }
if let Some(id) = tcx.plugin_registrar_fn(LOCAL_CRATE) { if let Some(id) = tcx.plugin_registrar_fn(()) {
reachable_non_generics.insert(id, SymbolExportLevel::C); reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
} }
reachable_non_generics reachable_non_generics
@ -174,7 +174,7 @@ fn exported_symbols_provider_local(
.map(|(&def_id, &level)| (ExportedSymbol::NonGeneric(def_id), level)) .map(|(&def_id, &level)| (ExportedSymbol::NonGeneric(def_id), level))
.collect(); .collect();
if tcx.entry_fn(LOCAL_CRATE).is_some() { if tcx.entry_fn(()).is_some() {
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main")); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main"));
symbols.push((exported_symbol, SymbolExportLevel::C)); symbols.push((exported_symbol, SymbolExportLevel::C));
@ -230,7 +230,7 @@ fn exported_symbols_provider_local(
// external linkage is enough for monomorphization to be linked to. // external linkage is enough for monomorphization to be linked to.
let need_visibility = tcx.sess.target.dynamic_linking && !tcx.sess.target.only_cdylib; let need_visibility = tcx.sess.target.dynamic_linking && !tcx.sess.target.only_cdylib;
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); let (_, cgus) = tcx.collect_and_partition_mono_items(());
for (mono_item, &(linkage, visibility)) in cgus.iter().flat_map(|cgu| cgu.items().iter()) { for (mono_item, &(linkage, visibility)) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
if linkage != Linkage::External { if linkage != Linkage::External {
@ -275,11 +275,9 @@ fn exported_symbols_provider_local(
fn upstream_monomorphizations_provider( fn upstream_monomorphizations_provider(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
cnum: CrateNum, (): (),
) -> DefIdMap<FxHashMap<SubstsRef<'_>, CrateNum>> { ) -> DefIdMap<FxHashMap<SubstsRef<'_>, CrateNum>> {
debug_assert!(cnum == LOCAL_CRATE); let cnums = tcx.all_crate_nums(());
let cnums = tcx.all_crate_nums(LOCAL_CRATE);
let mut instances: DefIdMap<FxHashMap<_, _>> = Default::default(); let mut instances: DefIdMap<FxHashMap<_, _>> = Default::default();
@ -341,7 +339,7 @@ fn upstream_monomorphizations_for_provider(
def_id: DefId, def_id: DefId,
) -> Option<&FxHashMap<SubstsRef<'_>, CrateNum>> { ) -> Option<&FxHashMap<SubstsRef<'_>, CrateNum>> {
debug_assert!(!def_id.is_local()); debug_assert!(!def_id.is_local());
tcx.upstream_monomorphizations(LOCAL_CRATE).get(&def_id) tcx.upstream_monomorphizations(()).get(&def_id)
} }
fn upstream_drop_glue_for_provider<'tcx>( fn upstream_drop_glue_for_provider<'tcx>(
@ -355,12 +353,8 @@ fn upstream_drop_glue_for_provider<'tcx>(
} }
} }
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool { fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
if let Some(def_id) = def_id.as_local() { !tcx.reachable_set(()).contains(&def_id)
!tcx.reachable_set(LOCAL_CRATE).contains(&def_id)
} else {
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
}
} }
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {

View file

@ -482,7 +482,7 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
codegen_worker_receive, codegen_worker_receive,
shared_emitter_main, shared_emitter_main,
future: coordinator_thread, future: coordinator_thread,
output_filenames: tcx.output_filenames(LOCAL_CRATE), output_filenames: tcx.output_filenames(()),
} }
} }
@ -1042,7 +1042,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
// If we know that we wont be doing codegen, create target machines without optimisation. // If we know that we wont be doing codegen, create target machines without optimisation.
config::OptLevel::No config::OptLevel::No
} else { } else {
tcx.backend_optimization_level(LOCAL_CRATE) tcx.backend_optimization_level(())
}; };
let cgcx = CodegenContext::<B> { let cgcx = CodegenContext::<B> {
backend: backend.clone(), backend: backend.clone(),
@ -1061,7 +1061,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
cgu_reuse_tracker: sess.cgu_reuse_tracker.clone(), cgu_reuse_tracker: sess.cgu_reuse_tracker.clone(),
coordinator_send, coordinator_send,
diag_emitter: shared_emitter.clone(), diag_emitter: shared_emitter.clone(),
output_filenames: tcx.output_filenames(LOCAL_CRATE), output_filenames: tcx.output_filenames(()),
regular_module_config: regular_config, regular_module_config: regular_config,
metadata_module_config: metadata_config, metadata_module_config: metadata_config,
allocator_module_config: allocator_config, allocator_module_config: allocator_config,

View file

@ -347,7 +347,7 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx, cx: &'a Bx::CodegenCx,
) -> Option<Bx::Function> { ) -> Option<Bx::Function> {
let main_def_id = cx.tcx().entry_fn(LOCAL_CRATE).map(|(def_id, _)| def_id)?; let (main_def_id, entry_type) = cx.tcx().entry_fn(())?;
let main_is_local = main_def_id.is_local(); let main_is_local = main_def_id.is_local();
let instance = Instance::mono(cx.tcx(), main_def_id); let instance = Instance::mono(cx.tcx(), main_def_id);
@ -364,10 +364,9 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let main_llfn = cx.get_fn_addr(instance); let main_llfn = cx.get_fn_addr(instance);
return cx.tcx().entry_fn(LOCAL_CRATE).map(|(_, et)| { let use_start_lang_item = EntryFnType::Start != entry_type;
let use_start_lang_item = EntryFnType::Start != et; let entry_fn = create_entry_fn::<Bx>(cx, main_llfn, main_def_id, use_start_lang_item);
create_entry_fn::<Bx>(cx, main_llfn, main_def_id, use_start_lang_item) return Some(entry_fn);
});
fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx, cx: &'a Bx::CodegenCx,
@ -487,7 +486,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
// Run the monomorphization collector and partition the collected items into // Run the monomorphization collector and partition the collected items into
// codegen units. // codegen units.
let codegen_units = tcx.collect_and_partition_mono_items(LOCAL_CRATE).1; let codegen_units = tcx.collect_and_partition_mono_items(()).1;
// Force all codegen_unit queries so they are already either red or green // Force all codegen_unit queries so they are already either red or green
// when compile_codegen_unit accesses them. We are not able to re-execute // when compile_codegen_unit accesses them. We are not able to re-execute
@ -512,7 +511,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
// linkage, then it's already got an allocator shim and we'll be using that // linkage, then it's already got an allocator shim and we'll be using that
// one instead. If nothing exists then it's our job to generate the // one instead. If nothing exists then it's our job to generate the
// allocator! // allocator!
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic) list.iter().any(|&linkage| linkage == Linkage::Dynamic)
}); });
@ -769,7 +768,7 @@ impl CrateInfo {
used_crate_source: Default::default(), used_crate_source: Default::default(),
lang_item_to_crate: Default::default(), lang_item_to_crate: Default::default(),
missing_lang_items: Default::default(), missing_lang_items: Default::default(),
dependency_formats: tcx.dependency_formats(LOCAL_CRATE), dependency_formats: tcx.dependency_formats(()),
}; };
let lang_items = tcx.lang_items(); let lang_items = tcx.lang_items();

View file

@ -21,7 +21,6 @@ use rustc_data_structures::sync::SeqCst;
use rustc_errors::registry::{InvalidErrorCode, Registry}; use rustc_errors::registry::{InvalidErrorCode, Registry};
use rustc_errors::{ErrorReported, PResult}; use rustc_errors::{ErrorReported, PResult};
use rustc_feature::find_gated_cfg; 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::util::{self, collect_crate_types, get_builtin_codegen_backend};
use rustc_interface::{interface, Queries}; use rustc_interface::{interface, Queries};
use rustc_lint::LintStore; use rustc_lint::LintStore;
@ -389,7 +388,7 @@ fn run_compiler(
} }
queries.global_ctxt()?.peek_mut().enter(|tcx| { queries.global_ctxt()?.peek_mut().enter(|tcx| {
let result = tcx.analysis(LOCAL_CRATE); let result = tcx.analysis(());
if sess.opts.debugging_opts.save_analysis { if sess.opts.debugging_opts.save_analysis {
let crate_name = queries.crate_name()?.peek().clone(); let crate_name = queries.crate_name()?.peek().clone();
sess.time("save_analysis", || { sess.time("save_analysis", || {

View file

@ -4,7 +4,6 @@ use rustc_ast as ast;
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_errors::ErrorReported; use rustc_errors::ErrorReported;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir_pretty as pprust_hir; use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map; use rustc_middle::hir::map as hir_map;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
@ -74,7 +73,7 @@ where
f(&annotation, tcx.hir().krate()) f(&annotation, tcx.hir().krate())
} }
PpHirMode::Typed => { 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) }; let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) };
tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate())) tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
@ -475,7 +474,7 @@ fn print_with_analysis(
ppm: PpMode, ppm: PpMode,
ofile: Option<&Path>, ofile: Option<&Path>,
) -> Result<(), ErrorReported> { ) -> Result<(), ErrorReported> {
tcx.analysis(LOCAL_CRATE)?; tcx.analysis(())?;
let out = match ppm { let out = match ppm {
Mir => { Mir => {

View file

@ -36,7 +36,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
} }
let available_cgus = tcx let available_cgus = tcx
.collect_and_partition_mono_items(LOCAL_CRATE) .collect_and_partition_mono_items(())
.1 .1
.iter() .iter()
.map(|cgu| cgu.name().to_string()) .map(|cgu| cgu.name().to_string())

View file

@ -12,7 +12,7 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel}; use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel};
use rustc_errors::{ErrorReported, PResult}; use rustc_errors::{ErrorReported, PResult};
use rustc_expand::base::ExtCtxt; 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_hir::Crate;
use rustc_lint::LintStore; use rustc_lint::LintStore;
use rustc_metadata::creader::CStore; use rustc_metadata::creader::CStore;
@ -805,9 +805,7 @@ pub fn create_global_ctxt<'tcx>(
/// Runs the resolution, type-checking, region checking and other /// Runs the resolution, type-checking, region checking and other
/// miscellaneous analysis passes on the crate. /// miscellaneous analysis passes on the crate.
fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
assert_eq!(cnum, LOCAL_CRATE);
rustc_passes::hir_id_validator::check_crate(tcx); rustc_passes::hir_id_validator::check_crate(tcx);
let sess = tcx.sess; let sess = tcx.sess;
@ -816,15 +814,14 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
sess.time("misc_checking_1", || { sess.time("misc_checking_1", || {
parallel!( parallel!(
{ {
entry_point = sess entry_point = sess.time("looking_for_entry_point", || tcx.entry_fn(()));
.time("looking_for_entry_point", || rustc_passes::entry::find_entry_point(tcx));
sess.time("looking_for_plugin_registrar", || { sess.time("looking_for_plugin_registrar", || tcx.ensure().plugin_registrar_fn(()));
plugin::build::find_plugin_registrar(tcx)
sess.time("looking_for_derive_registrar", || {
tcx.ensure().proc_macro_decls_static(())
}); });
sess.time("looking_for_derive_registrar", || proc_macro_decls::find(tcx));
let cstore = tcx let cstore = tcx
.cstore_as_any() .cstore_as_any()
.downcast_ref::<CStore>() .downcast_ref::<CStore>()
@ -903,11 +900,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
sess.time("misc_checking_3", || { sess.time("misc_checking_3", || {
parallel!( parallel!(
{ {
tcx.ensure().privacy_access_levels(LOCAL_CRATE); tcx.ensure().privacy_access_levels(());
parallel!( parallel!(
{ {
tcx.ensure().check_private_in_public(LOCAL_CRATE); tcx.ensure().check_private_in_public(());
}, },
{ {
sess.time("death_checking", || rustc_passes::dead::check_crate(tcx)); sess.time("death_checking", || rustc_passes::dead::check_crate(tcx));

View file

@ -1,21 +1,15 @@
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::LocalDefId;
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
pub fn find(tcx: TyCtxt<'_>) -> Option<DefId> { fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
tcx.proc_macro_decls_static(LOCAL_CRATE)
}
fn proc_macro_decls_static(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
assert_eq!(cnum, LOCAL_CRATE);
let mut finder = Finder { tcx, decls: None }; let mut finder = Finder { tcx, decls: None };
tcx.hir().krate().visit_all_item_likes(&mut finder); tcx.hir().krate().visit_all_item_likes(&mut finder);
finder.decls.map(|id| tcx.hir().local_def_id(id).to_def_id()) finder.decls.map(|id| tcx.hir().local_def_id(id))
} }
struct Finder<'tcx> { struct Finder<'tcx> {

View file

@ -285,7 +285,7 @@ impl<'tcx> Queries<'tcx> {
self.ongoing_codegen.compute(|| { self.ongoing_codegen.compute(|| {
let outputs = self.prepare_outputs()?; let outputs = self.prepare_outputs()?;
self.global_ctxt()?.peek_mut().enter(|tcx| { 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 // Don't do code generation if there were any errors
self.session().compile_status()?; self.session().compile_status()?;
@ -302,7 +302,7 @@ impl<'tcx> Queries<'tcx> {
/// to write UI tests that actually test that compilation succeeds without reporting /// to write UI tests that actually test that compilation succeeds without reporting
/// an error. /// an error.
fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) { fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
let def_id = match tcx.entry_fn(LOCAL_CRATE) { let def_id = match tcx.entry_fn(()) {
Some((def_id, _)) => def_id, Some((def_id, _)) => def_id,
_ => return, _ => return,
}; };

View file

@ -18,7 +18,7 @@ use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::sync::{join, par_iter, ParallelIterator}; use rustc_data_structures::sync::{join, par_iter, ParallelIterator};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit as hir_visit; use rustc_hir::intravisit as hir_visit;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
@ -375,7 +375,7 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
module_def_id: LocalDefId, module_def_id: LocalDefId,
pass: T, pass: T,
) { ) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); let access_levels = &tcx.privacy_access_levels(());
let context = LateContext { let context = LateContext {
tcx, tcx,
@ -423,7 +423,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx>>(
} }
fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T) { fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); let access_levels = &tcx.privacy_access_levels(());
let krate = tcx.hir().krate(); let krate = tcx.hir().krate();

View file

@ -6,8 +6,7 @@ use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::{intravisit, HirId, CRATE_HIR_ID};
use rustc_hir::{intravisit, HirId};
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
use rustc_middle::lint::LevelAndSource; use rustc_middle::lint::LevelAndSource;
use rustc_middle::lint::LintDiagnosticBuilder; use rustc_middle::lint::LintDiagnosticBuilder;
@ -28,10 +27,9 @@ use tracing::debug;
use std::cmp; use std::cmp;
fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> LintLevelMap { fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
assert_eq!(cnum, LOCAL_CRATE);
let store = unerased_lint_store(tcx); let store = unerased_lint_store(tcx);
let crate_attrs = tcx.get_attrs(DefId { krate: cnum, index: CRATE_DEF_INDEX }); let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
let levels = LintLevelsBuilder::new(tcx.sess, false, &store, crate_attrs); let levels = LintLevelsBuilder::new(tcx.sess, false, &store, crate_attrs);
let mut builder = LintLevelMapBuilder { levels, tcx, store }; let mut builder = LintLevelMapBuilder { levels, tcx, store };
let krate = tcx.hir().krate(); let krate = tcx.hir().krate();

View file

@ -185,19 +185,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
} }
native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) } native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) }
foreign_modules => { cdata.get_foreign_modules(tcx) } foreign_modules => { cdata.get_foreign_modules(tcx) }
plugin_registrar_fn => {
cdata.root.plugin_registrar_fn.map(|index| {
DefId { krate: def_id.krate, index }
})
}
proc_macro_decls_static => {
cdata.root.proc_macro_data.as_ref().map(|data| {
DefId {
krate: def_id.krate,
index: data.proc_macro_decls_static,
}
})
}
crate_disambiguator => { cdata.root.disambiguator } crate_disambiguator => { cdata.root.disambiguator }
crate_hash => { cdata.root.hash } crate_hash => { cdata.root.hash }
crate_host_hash => { cdata.host_hash } crate_host_hash => { cdata.host_hash }
@ -296,11 +283,10 @@ pub fn provide(providers: &mut Providers) {
// external item that is visible from at least one local module) to a // external item that is visible from at least one local module) to a
// sufficiently visible parent (considering modules that re-export the // sufficiently visible parent (considering modules that re-export the
// external item to be parents). // external item to be parents).
visible_parent_map: |tcx, cnum| { visible_parent_map: |tcx, ()| {
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::vec_deque::VecDeque; use std::collections::vec_deque::VecDeque;
assert_eq!(cnum, LOCAL_CRATE);
let mut visible_parent_map: DefIdMap<DefId> = Default::default(); let mut visible_parent_map: DefIdMap<DefId> = Default::default();
// Issue 46112: We want the map to prefer the shortest // Issue 46112: We want the map to prefer the shortest
@ -348,7 +334,7 @@ pub fn provide(providers: &mut Providers) {
Entry::Occupied(mut entry) => { Entry::Occupied(mut entry) => {
// If `child` is defined in crate `cnum`, ensure // If `child` is defined in crate `cnum`, ensure
// that it is mapped to a parent in `cnum`. // that it is mapped to a parent in `cnum`.
if child.krate == cnum && entry.get().krate != cnum { if child.is_local() && entry.get().is_local() {
entry.insert(parent); entry.insert(parent);
} }
} }
@ -370,17 +356,14 @@ pub fn provide(providers: &mut Providers) {
visible_parent_map visible_parent_map
}, },
dependency_formats: |tcx, cnum| { dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)),
assert_eq!(cnum, LOCAL_CRATE);
Lrc::new(crate::dependency_format::calculate(tcx))
},
has_global_allocator: |tcx, cnum| { has_global_allocator: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE); assert_eq!(cnum, LOCAL_CRATE);
CStore::from_tcx(tcx).has_global_allocator() CStore::from_tcx(tcx).has_global_allocator()
}, },
postorder_cnums: |tcx, cnum| { postorder_cnums: |tcx, ()| {
assert_eq!(cnum, LOCAL_CRATE); tcx.arena
tcx.arena.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(cnum)) .alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
}, },
..*providers ..*providers

View file

@ -678,7 +678,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE), has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE), has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
has_default_lib_allocator, has_default_lib_allocator,
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
proc_macro_data, proc_macro_data,
compiler_builtins: tcx.sess.contains_name(&attrs, sym::compiler_builtins), compiler_builtins: tcx.sess.contains_name(&attrs, sym::compiler_builtins),
needs_allocator: tcx.sess.contains_name(&attrs, sym::needs_allocator), needs_allocator: tcx.sess.contains_name(&attrs, sym::needs_allocator),
@ -970,13 +969,12 @@ impl EncodeContext<'a, 'tcx> {
record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id)); record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id));
} }
} }
let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE); let inherent_impls = tcx.crate_inherent_impls(());
for (def_id, implementations) in inherent_impls.inherent_impls.iter() { for (def_id, implementations) in inherent_impls.inherent_impls.iter() {
assert!(def_id.is_local());
if implementations.is_empty() { if implementations.is_empty() {
continue; continue;
} }
record!(self.tables.inherent_impls[def_id] <- implementations.iter().map(|&def_id| { record!(self.tables.inherent_impls[def_id.to_def_id()] <- implementations.iter().map(|&def_id| {
assert!(def_id.is_local()); assert!(def_id.is_local());
def_id.index def_id.index
})); }));
@ -1263,7 +1261,7 @@ impl EncodeContext<'a, 'tcx> {
let mut keys_and_jobs = self let mut keys_and_jobs = self
.tcx .tcx
.mir_keys(LOCAL_CRATE) .mir_keys(())
.iter() .iter()
.filter_map(|&def_id| { .filter_map(|&def_id| {
let (encode_const, encode_opt) = should_encode_mir(self.tcx, def_id); let (encode_const, encode_opt) = should_encode_mir(self.tcx, def_id);
@ -1601,7 +1599,7 @@ impl EncodeContext<'a, 'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
let hir = tcx.hir(); let hir = tcx.hir();
let proc_macro_decls_static = tcx.proc_macro_decls_static(LOCAL_CRATE).unwrap().index; let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
let stability = tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).copied(); let stability = tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).copied();
let macros = self.lazy(hir.krate().proc_macros.iter().map(|p| p.owner.local_def_index)); let macros = self.lazy(hir.krate().proc_macros.iter().map(|p| p.owner.local_def_index));
let spans = self.tcx.sess.parse_sess.proc_macro_quoted_spans(); let spans = self.tcx.sess.parse_sess.proc_macro_quoted_spans();
@ -1798,7 +1796,7 @@ impl EncodeContext<'a, 'tcx> {
fn encode_dylib_dependency_formats(&mut self) -> Lazy<[Option<LinkagePreference>]> { fn encode_dylib_dependency_formats(&mut self) -> Lazy<[Option<LinkagePreference>]> {
empty_proc_macro!(self); empty_proc_macro!(self);
let formats = self.tcx.dependency_formats(LOCAL_CRATE); let formats = self.tcx.dependency_formats(());
for (ty, arr) in formats.iter() { for (ty, arr) in formats.iter() {
if *ty != CrateType::Dylib { if *ty != CrateType::Dylib {
continue; continue;
@ -2028,7 +2026,7 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
return; return;
} }
par_iter(tcx.mir_keys(LOCAL_CRATE)).for_each(|&def_id| { par_iter(tcx.mir_keys(())).for_each(|&def_id| {
let (encode_const, encode_opt) = should_encode_mir(tcx, def_id); let (encode_const, encode_opt) = should_encode_mir(tcx, def_id);
if encode_const { if encode_const {

View file

@ -209,7 +209,6 @@ crate struct CrateRoot<'tcx> {
has_global_allocator: bool, has_global_allocator: bool,
has_panic_handler: bool, has_panic_handler: bool,
has_default_lib_allocator: bool, has_default_lib_allocator: bool,
plugin_registrar_fn: Option<DefIndex>,
crate_deps: Lazy<[CrateDep]>, crate_deps: Lazy<[CrateDep]>,
dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>, dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>,

View file

@ -150,7 +150,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'_, 'hir> {
impl<'hir> Map<'hir> { impl<'hir> Map<'hir> {
pub fn krate(&self) -> &'hir Crate<'hir> { pub fn krate(&self) -> &'hir Crate<'hir> {
self.tcx.hir_crate(LOCAL_CRATE) self.tcx.hir_crate(())
} }
#[inline] #[inline]
@ -489,7 +489,7 @@ impl<'hir> Map<'hir> {
} }
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [LocalDefId] { pub fn trait_impls(&self, trait_did: DefId) -> &'hir [LocalDefId] {
self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..]) self.tcx.all_local_trait_impls(()).get(&trait_did).map_or(&[], |xs| &xs[..])
} }
/// Gets the attributes on the crate. This is preferable to /// Gets the attributes on the crate. This is preferable to
@ -928,9 +928,7 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
} }
} }
pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx IndexedHir<'tcx> { pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexedHir<'tcx> {
assert_eq!(cnum, LOCAL_CRATE);
let _prof_timer = tcx.sess.prof.generic_activity("build_hir_map"); let _prof_timer = tcx.sess.prof.generic_activity("build_hir_map");
let hcx = tcx.create_stable_hashing_context(); let hcx = tcx.create_stable_hashing_context();
@ -943,10 +941,12 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
} }
pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
assert_eq!(crate_num, LOCAL_CRATE);
let mut hcx = tcx.create_stable_hashing_context(); let mut hcx = tcx.create_stable_hashing_context();
let mut hir_body_nodes: Vec<_> = tcx let mut hir_body_nodes: Vec<_> = tcx
.index_hir(crate_num) .index_hir(())
.map .map
.iter_enumerated() .iter_enumerated()
.filter_map(|(def_id, hod)| { .filter_map(|(def_id, hod)| {

View file

@ -13,7 +13,7 @@ use rustc_ast::Attribute;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::LocalDefId;
use rustc_hir::*; use rustc_hir::*;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
@ -123,14 +123,14 @@ pub fn provide(providers: &mut Providers) {
let hir = tcx.hir(); let hir = tcx.hir();
hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id))) hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)))
}; };
providers.hir_crate = |tcx, _| tcx.untracked_crate; providers.hir_crate = |tcx, ()| tcx.untracked_crate;
providers.index_hir = map::index_hir; providers.index_hir = map::index_hir;
providers.crate_hash = map::crate_hash; providers.crate_hash = map::crate_hash;
providers.hir_module_items = |tcx, id| &tcx.untracked_crate.modules[&id]; providers.hir_module_items = |tcx, id| &tcx.untracked_crate.modules[&id];
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature; providers.hir_owner = |tcx, id| tcx.index_hir(()).map[id].signature;
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref(); providers.hir_owner_nodes = |tcx, id| tcx.index_hir(()).map[id].with_bodies.as_deref();
providers.hir_owner_parent = |tcx, id| { providers.hir_owner_parent = |tcx, id| {
let index = tcx.index_hir(LOCAL_CRATE); let index = tcx.index_hir(());
index.parenting.get(&id).copied().unwrap_or(CRATE_HIR_ID) index.parenting.get(&id).copied().unwrap_or(CRATE_HIR_ID)
}; };
providers.hir_attrs = |tcx, id| AttributeMap { map: &tcx.untracked_crate.attrs, prefix: id }; providers.hir_attrs = |tcx, id| AttributeMap { map: &tcx.untracked_crate.attrs, prefix: id };
@ -151,4 +151,5 @@ pub fn provide(providers: &mut Providers) {
} }
}; };
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local()); providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
providers.all_local_trait_impls = |tcx, ()| &tcx.hir_crate(()).trait_impls;
} }

View file

@ -251,7 +251,7 @@ pub fn used_crates(tcx: TyCtxt<'_>, prefer: LinkagePreference) -> Vec<(CrateNum,
Some((cnum, path)) Some((cnum, path))
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE).to_owned(); let mut ordering = tcx.postorder_cnums(()).to_owned();
ordering.reverse(); ordering.reverse();
libs.sort_by_cached_key(|&(a, _)| ordering.iter().position(|x| *x == a)); libs.sort_by_cached_key(|&(a, _)| ordering.iter().position(|x| *x == a));
libs libs

View file

@ -88,7 +88,7 @@ impl<'tcx> MonoItem<'tcx> {
match *self { match *self {
MonoItem::Fn(ref instance) => { MonoItem::Fn(ref instance) => {
let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id); let entry_def_id = tcx.entry_fn(()).map(|(id, _)| id);
// If this function isn't inlined or otherwise has an extern // If this function isn't inlined or otherwise has an extern
// indicator, then we'll be creating a globally shared version. // indicator, then we'll be creating a globally shared version.
if tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator() if tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()

View file

@ -20,7 +20,7 @@ rustc_queries! {
/// This is because the `hir_crate` query gives you access to all other items. /// This is because the `hir_crate` query gives you access to all other items.
/// To avoid this fate, do not call `tcx.hir().krate()`; instead, /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
/// prefer wrappers like `tcx.visit_all_items_in_krate()`. /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
query hir_crate(key: CrateNum) -> &'tcx Crate<'tcx> { query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
eval_always eval_always
no_hash no_hash
desc { "get the crate HIR" } desc { "get the crate HIR" }
@ -28,7 +28,7 @@ rustc_queries! {
/// The indexed HIR. This can be conveniently accessed by `tcx.hir()`. /// The indexed HIR. This can be conveniently accessed by `tcx.hir()`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query index_hir(_: CrateNum) -> &'tcx crate::hir::IndexedHir<'tcx> { query index_hir(_: ()) -> &'tcx crate::hir::IndexedHir<'tcx> {
eval_always eval_always
no_hash no_hash
desc { "index HIR" } desc { "index HIR" }
@ -114,7 +114,7 @@ rustc_queries! {
cache_on_disk_if { key.is_local() } cache_on_disk_if { key.is_local() }
} }
query analysis(key: CrateNum) -> Result<(), ErrorReported> { query analysis(key: ()) -> Result<(), ErrorReported> {
eval_always eval_always
desc { "running analysis passes on this crate" } desc { "running analysis passes on this crate" }
} }
@ -199,7 +199,7 @@ rustc_queries! {
desc { "looking up the native libraries of a linked crate" } desc { "looking up the native libraries of a linked crate" }
} }
query lint_levels(_: CrateNum) -> LintLevelMap { query lint_levels(_: ()) -> LintLevelMap {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
eval_always eval_always
desc { "computing the lint levels for items in this crate" } desc { "computing the lint levels for items in this crate" }
@ -223,7 +223,7 @@ rustc_queries! {
/// Set of all the `DefId`s in this crate that have MIR associated with /// Set of all the `DefId`s in this crate that have MIR associated with
/// them. This includes all the body owners, but also things like struct /// them. This includes all the body owners, but also things like struct
/// constructors. /// constructors.
query mir_keys(_: CrateNum) -> FxHashSet<LocalDefId> { query mir_keys(_: ()) -> FxHashSet<LocalDefId> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
desc { "getting a list of all mir_keys" } desc { "getting a list of all mir_keys" }
} }
@ -543,7 +543,7 @@ rustc_queries! {
} }
/// Gets a map with the variance of every item; use `item_variance` instead. /// Gets a map with the variance of every item; use `item_variance` instead.
query crate_variances(_: CrateNum) -> ty::CrateVariancesMap<'tcx> { query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
desc { "computing the variances for items in this crate" } desc { "computing the variances for items in this crate" }
} }
@ -554,8 +554,7 @@ rustc_queries! {
} }
/// Maps from thee `DefId` of a type to its (inferred) outlives. /// Maps from thee `DefId` of a type to its (inferred) outlives.
query inferred_outlives_crate(_: CrateNum) query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
-> ty::CratePredicatesMap<'tcx> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
desc { "computing the inferred outlives predicates for items in this crate" } desc { "computing the inferred outlives predicates for items in this crate" }
} }
@ -694,7 +693,7 @@ rustc_queries! {
desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) } desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
} }
query typeck_item_bodies(_: CrateNum) -> () { query typeck_item_bodies(_: ()) -> () {
desc { "type-checking all item bodies" } desc { "type-checking all item bodies" }
} }
@ -753,18 +752,15 @@ rustc_queries! {
/// Gets a complete map from all types to their inherent impls. /// Gets a complete map from all types to their inherent impls.
/// Not meant to be used directly outside of coherence. /// Not meant to be used directly outside of coherence.
/// (Defined only for `LOCAL_CRATE`.) query crate_inherent_impls(k: ()) -> CrateInherentImpls {
query crate_inherent_impls(k: CrateNum)
-> CrateInherentImpls {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
eval_always eval_always
desc { "all inherent impls defined in crate `{:?}`", k } desc { "all inherent impls defined in crate" }
} }
/// Checks all types in the crate for overlap in their inherent impls. Reports errors. /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
/// Not meant to be used directly outside of coherence. /// Not meant to be used directly outside of coherence.
/// (Defined only for `LOCAL_CRATE`.) query crate_inherent_impls_overlap_check(_: ())
query crate_inherent_impls_overlap_check(_: CrateNum)
-> () { -> () {
eval_always eval_always
desc { "check for overlap between inherent impls defined in this crate" } desc { "check for overlap between inherent impls defined in this crate" }
@ -858,16 +854,16 @@ rustc_queries! {
} }
/// Performs part of the privacy check and computes "access levels". /// Performs part of the privacy check and computes "access levels".
query privacy_access_levels(_: CrateNum) -> &'tcx AccessLevels { query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
eval_always eval_always
desc { "privacy access levels" } desc { "privacy access levels" }
} }
query check_private_in_public(_: CrateNum) -> () { query check_private_in_public(_: ()) -> () {
eval_always eval_always
desc { "checking for private elements in public interfaces" } desc { "checking for private elements in public interfaces" }
} }
query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> { query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
desc { "reachability" } desc { "reachability" }
} }
@ -977,7 +973,7 @@ rustc_queries! {
/// Passing in any other crate will cause an ICE. /// Passing in any other crate will cause an ICE.
/// ///
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE /// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> { query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
desc { "local trait impls" } desc { "local trait impls" }
} }
@ -1080,9 +1076,7 @@ rustc_queries! {
desc { "dylib dependency formats of crate" } desc { "dylib dependency formats of crate" }
} }
query dependency_formats(_: CrateNum) query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
-> Lrc<crate::middle::dependency_format::Dependencies>
{
desc { "get the linkage format of all dependencies" } desc { "get the linkage format of all dependencies" }
} }
@ -1170,10 +1164,10 @@ rustc_queries! {
query is_reachable_non_generic(def_id: DefId) -> bool { query is_reachable_non_generic(def_id: DefId) -> bool {
desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) } desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
} }
query is_unreachable_local_definition(def_id: DefId) -> bool { query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
desc { |tcx| desc { |tcx|
"checking whether `{}` is reachable from outside the crate", "checking whether `{}` is reachable from outside the crate",
tcx.def_path_str(def_id), tcx.def_path_str(def_id.to_def_id()),
} }
} }
@ -1183,11 +1177,9 @@ rustc_queries! {
/// added or removed in any upstream crate. Instead use the narrower /// added or removed in any upstream crate. Instead use the narrower
/// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
/// better, `Instance::upstream_monomorphization()`. /// better, `Instance::upstream_monomorphization()`.
query upstream_monomorphizations( query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
k: CrateNum
) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
desc { "collecting available upstream monomorphizations `{:?}`", k } desc { "collecting available upstream monomorphizations" }
} }
/// Returns the set of upstream monomorphizations available for the /// Returns the set of upstream monomorphizations available for the
@ -1230,13 +1222,13 @@ rustc_queries! {
/// Identifies the entry-point (e.g., the `main` function) for a given /// Identifies the entry-point (e.g., the `main` function) for a given
/// crate, returning `None` if there is no entry point (such as for library crates). /// crate, returning `None` if there is no entry point (such as for library crates).
query entry_fn(_: CrateNum) -> Option<(DefId, EntryFnType)> { query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
desc { "looking up the entry function of a crate" } desc { "looking up the entry function of a crate" }
} }
query plugin_registrar_fn(_: CrateNum) -> Option<DefId> { query plugin_registrar_fn(_: ()) -> Option<LocalDefId> {
desc { "looking up the plugin registrar for a crate" } desc { "looking up the plugin registrar for a crate" }
} }
query proc_macro_decls_static(_: CrateNum) -> Option<DefId> { query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
desc { "looking up the derive registrar for a crate" } desc { "looking up the derive registrar for a crate" }
} }
query crate_disambiguator(_: CrateNum) -> CrateDisambiguator { query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
@ -1363,7 +1355,7 @@ rustc_queries! {
desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) } desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
} }
query get_lib_features(_: CrateNum) -> LibFeatures { query get_lib_features(_: ()) -> LibFeatures {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
eval_always eval_always
desc { "calculating the lib features map" } desc { "calculating the lib features map" }
@ -1373,16 +1365,14 @@ rustc_queries! {
desc { "calculating the lib features defined in a crate" } desc { "calculating the lib features defined in a crate" }
} }
/// Returns the lang items defined in another crate by loading it from metadata. /// Returns the lang items defined in another crate by loading it from metadata.
// FIXME: It is illegal to pass a `CrateNum` other than `LOCAL_CRATE` here, just get rid query get_lang_items(_: ()) -> LanguageItems {
// of that argument?
query get_lang_items(_: CrateNum) -> LanguageItems {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
eval_always eval_always
desc { "calculating the lang items map" } desc { "calculating the lang items map" }
} }
/// Returns all diagnostic items defined in all crates. /// Returns all diagnostic items defined in all crates.
query all_diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> { query all_diagnostic_items(_: ()) -> FxHashMap<Symbol, DefId> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
eval_always eval_always
desc { "calculating the diagnostic items map" } desc { "calculating the diagnostic items map" }
@ -1402,13 +1392,11 @@ rustc_queries! {
query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] { query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
desc { "calculating the missing lang items in a crate" } desc { "calculating the missing lang items in a crate" }
} }
query visible_parent_map(_: CrateNum) query visible_parent_map(_: ()) -> DefIdMap<DefId> {
-> DefIdMap<DefId> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
desc { "calculating the visible parent map" } desc { "calculating the visible parent map" }
} }
query trimmed_def_paths(_: CrateNum) query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
-> FxHashMap<DefId, Symbol> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
desc { "calculating trimmed def paths" } desc { "calculating trimmed def paths" }
} }
@ -1420,7 +1408,7 @@ rustc_queries! {
eval_always eval_always
desc { "looking at the source for a crate" } desc { "looking at the source for a crate" }
} }
query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] { query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
eval_always eval_always
desc { "generating a postorder list of CrateNums" } desc { "generating a postorder list of CrateNums" }
} }
@ -1433,8 +1421,7 @@ rustc_queries! {
eval_always eval_always
desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) } desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
} }
query maybe_unused_extern_crates(_: CrateNum) query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
-> &'tcx [(LocalDefId, Span)] {
eval_always eval_always
desc { "looking up all possibly unused extern crates" } desc { "looking up all possibly unused extern crates" }
} }
@ -1444,12 +1431,12 @@ rustc_queries! {
desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) } desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
} }
query stability_index(_: CrateNum) -> stability::Index<'tcx> { query stability_index(_: ()) -> stability::Index<'tcx> {
storage(ArenaCacheSelector<'tcx>) storage(ArenaCacheSelector<'tcx>)
eval_always eval_always
desc { "calculating the stability index for the local crate" } desc { "calculating the stability index for the local crate" }
} }
query all_crate_nums(_: CrateNum) -> &'tcx [CrateNum] { query all_crate_nums(_: ()) -> &'tcx [CrateNum] {
eval_always eval_always
desc { "fetching all foreign CrateNum instances" } desc { "fetching all foreign CrateNum instances" }
} }
@ -1457,7 +1444,7 @@ rustc_queries! {
/// A vector of every trait accessible in the whole crate /// A vector of every trait accessible in the whole crate
/// (i.e., including those from subcrates). This is used only for /// (i.e., including those from subcrates). This is used only for
/// error reporting. /// error reporting.
query all_traits(_: CrateNum) -> &'tcx [DefId] { query all_traits(_: ()) -> &'tcx [DefId] {
desc { "fetching all foreign and local traits" } desc { "fetching all foreign and local traits" }
} }
@ -1471,8 +1458,7 @@ rustc_queries! {
desc { "exported_symbols" } desc { "exported_symbols" }
} }
query collect_and_partition_mono_items(_: CrateNum) query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
-> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
eval_always eval_always
desc { "collect_and_partition_mono_items" } desc { "collect_and_partition_mono_items" }
} }
@ -1481,8 +1467,7 @@ rustc_queries! {
} }
/// All items participating in code generation together with items inlined into them. /// All items participating in code generation together with items inlined into them.
query codegened_and_inlined_items(_: CrateNum) query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
-> &'tcx DefIdSet {
eval_always eval_always
desc { "codegened_and_inlined_items" } desc { "codegened_and_inlined_items" }
} }
@ -1497,11 +1482,11 @@ rustc_queries! {
tcx.def_path_str(key) tcx.def_path_str(key)
} }
} }
query backend_optimization_level(_: CrateNum) -> OptLevel { query backend_optimization_level(_: ()) -> OptLevel {
desc { "optimization level used by backend" } desc { "optimization level used by backend" }
} }
query output_filenames(_: CrateNum) -> Arc<OutputFilenames> { query output_filenames(_: ()) -> Arc<OutputFilenames> {
eval_always eval_always
desc { "output_filenames" } desc { "output_filenames" }
} }
@ -1677,7 +1662,7 @@ rustc_queries! {
desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) } desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
} }
query features_query(_: CrateNum) -> &'tcx rustc_feature::Features { query features_query(_: ()) -> &'tcx rustc_feature::Features {
eval_always eval_always
desc { "looking up enabled feature gates" } desc { "looking up enabled feature gates" }
} }

View file

@ -1218,18 +1218,18 @@ impl<'tcx> TyCtxt<'tcx> {
} }
pub fn lib_features(self) -> &'tcx middle::lib_features::LibFeatures { pub fn lib_features(self) -> &'tcx middle::lib_features::LibFeatures {
self.get_lib_features(LOCAL_CRATE) self.get_lib_features(())
} }
/// Obtain all lang items of this crate and all dependencies (recursively) /// Obtain all lang items of this crate and all dependencies (recursively)
pub fn lang_items(self) -> &'tcx rustc_hir::lang_items::LanguageItems { pub fn lang_items(self) -> &'tcx rustc_hir::lang_items::LanguageItems {
self.get_lang_items(LOCAL_CRATE) self.get_lang_items(())
} }
/// Obtain the given diagnostic item's `DefId`. Use `is_diagnostic_item` if you just want to /// Obtain the given diagnostic item's `DefId`. Use `is_diagnostic_item` if you just want to
/// compare against another `DefId`, since `is_diagnostic_item` is cheaper. /// compare against another `DefId`, since `is_diagnostic_item` is cheaper.
pub fn get_diagnostic_item(self, name: Symbol) -> Option<DefId> { pub fn get_diagnostic_item(self, name: Symbol) -> Option<DefId> {
self.all_diagnostic_items(LOCAL_CRATE).get(&name).copied() self.all_diagnostic_items(()).get(&name).copied()
} }
/// Check whether the diagnostic item with the given `name` has the given `DefId`. /// Check whether the diagnostic item with the given `name` has the given `DefId`.
@ -1238,11 +1238,11 @@ impl<'tcx> TyCtxt<'tcx> {
} }
pub fn stability(self) -> &'tcx stability::Index<'tcx> { pub fn stability(self) -> &'tcx stability::Index<'tcx> {
self.stability_index(LOCAL_CRATE) self.stability_index(())
} }
pub fn crates(self) -> &'tcx [CrateNum] { pub fn crates(self) -> &'tcx [CrateNum] {
self.all_crate_nums(LOCAL_CRATE) self.all_crate_nums(())
} }
pub fn allocator_kind(self) -> Option<AllocatorKind> { pub fn allocator_kind(self) -> Option<AllocatorKind> {
@ -1250,7 +1250,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
pub fn features(self) -> &'tcx rustc_feature::Features { pub fn features(self) -> &'tcx rustc_feature::Features {
self.features_query(LOCAL_CRATE) self.features_query(())
} }
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey { pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
@ -2623,7 +2623,7 @@ impl<'tcx> TyCtxt<'tcx> {
lint: &'static Lint, lint: &'static Lint,
mut id: hir::HirId, mut id: hir::HirId,
) -> (Level, LintLevelSource) { ) -> (Level, LintLevelSource) {
let sets = self.lint_levels(LOCAL_CRATE); let sets = self.lint_levels(());
loop { loop {
if let Some(pair) = sets.level_and_source(lint, id, self.sess) { if let Some(pair) = sets.level_and_source(lint, id, self.sess) {
return pair; return pair;
@ -2795,10 +2795,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
tcx.crate_name tcx.crate_name
}; };
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id); providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
providers.maybe_unused_extern_crates = |tcx, cnum| { providers.maybe_unused_extern_crates = |tcx, ()| &tcx.maybe_unused_extern_crates[..];
assert_eq!(cnum, LOCAL_CRATE);
&tcx.maybe_unused_extern_crates[..]
};
providers.names_imported_by_glob_use = providers.names_imported_by_glob_use =
|tcx, id| tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default()); |tcx, id| tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default());
@ -2815,18 +2812,9 @@ pub fn provide(providers: &mut ty::query::Providers) {
tcx.stability().local_deprecation_entry(id) tcx.stability().local_deprecation_entry(id)
}; };
providers.extern_mod_stmt_cnum = |tcx, id| tcx.extern_crate_map.get(&id).cloned(); providers.extern_mod_stmt_cnum = |tcx, id| tcx.extern_crate_map.get(&id).cloned();
providers.all_crate_nums = |tcx, cnum| { providers.all_crate_nums = |tcx, ()| tcx.arena.alloc_slice(&tcx.cstore.crates_untracked());
assert_eq!(cnum, LOCAL_CRATE); providers.output_filenames = |tcx, ()| tcx.output_filenames.clone();
tcx.arena.alloc_slice(&tcx.cstore.crates_untracked()) providers.features_query = |tcx, ()| tcx.sess.features_untracked();
};
providers.output_filenames = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
tcx.output_filenames.clone()
};
providers.features_query = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
tcx.sess.features_untracked()
};
providers.is_panic_runtime = |tcx, cnum| { providers.is_panic_runtime = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE); assert_eq!(cnum, LOCAL_CRATE);
tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime) tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime)

View file

@ -36,7 +36,7 @@ use rustc_data_structures::sync::{self, par_iter, ParallelIterator};
use rustc_data_structures::tagged_ptr::CopyTaggedPtr; use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_INDEX};
use rustc_hir::{Constness, Node}; use rustc_hir::{Constness, Node};
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_span::hygiene::ExpnId; use rustc_span::hygiene::ExpnId;
@ -1970,7 +1970,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
super::util::bug::provide(providers); super::util::bug::provide(providers);
*providers = ty::query::Providers { *providers = ty::query::Providers {
trait_impls_of: trait_def::trait_impls_of_provider, trait_impls_of: trait_def::trait_impls_of_provider,
all_local_trait_impls: trait_def::all_local_trait_impls,
type_uninhabited_from: inhabitedness::type_uninhabited_from, type_uninhabited_from: inhabitedness::type_uninhabited_from,
const_param_default: consts::const_param_default, const_param_default: consts::const_param_default,
..*providers ..*providers
@ -1984,7 +1983,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
/// (constructing this map requires touching the entire crate). /// (constructing this map requires touching the entire crate).
#[derive(Clone, Debug, Default, HashStable)] #[derive(Clone, Debug, Default, HashStable)]
pub struct CrateInherentImpls { pub struct CrateInherentImpls {
pub inherent_impls: DefIdMap<Vec<DefId>>, pub inherent_impls: LocalDefIdMap<Vec<DefId>>,
} }
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]

View file

@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::sso::SsoHashSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{self, CtorKind, DefKind, Namespace}; use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData}; use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
use rustc_hir::ItemKind; use rustc_hir::ItemKind;
use rustc_session::config::TrimmedDefPaths; use rustc_session::config::TrimmedDefPaths;
@ -285,7 +285,7 @@ pub trait PrettyPrinter<'tcx>:
return Ok((self, false)); return Ok((self, false));
} }
match self.tcx().trimmed_def_paths(LOCAL_CRATE).get(&def_id) { match self.tcx().trimmed_def_paths(()).get(&def_id) {
None => Ok((self, false)), None => Ok((self, false)),
Some(symbol) => { Some(symbol) => {
self.write_str(&symbol.as_str())?; self.write_str(&symbol.as_str())?;
@ -361,7 +361,7 @@ pub trait PrettyPrinter<'tcx>:
return Ok((self, false)); return Ok((self, false));
} }
let visible_parent_map = self.tcx().visible_parent_map(LOCAL_CRATE); let visible_parent_map = self.tcx().visible_parent_map(());
let mut cur_def_key = self.tcx().def_key(def_id); let mut cur_def_key = self.tcx().def_key(def_id);
debug!("try_print_visible_def_path: cur_def_key={:?}", cur_def_key); debug!("try_print_visible_def_path: cur_def_key={:?}", cur_def_key);
@ -2302,9 +2302,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
/// `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. /// `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere.
/// ///
/// The implementation uses similar import discovery logic to that of 'use' suggestions. /// The implementation uses similar import discovery logic to that of 'use' suggestions.
fn trimmed_def_paths(tcx: TyCtxt<'_>, crate_num: CrateNum) -> FxHashMap<DefId, Symbol> { fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> {
assert_eq!(crate_num, LOCAL_CRATE);
let mut map = FxHashMap::default(); let mut map = FxHashMap::default();
if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths { if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths {

View file

@ -579,7 +579,7 @@ impl<'sess> OnDiskCache<'sess> {
) -> IndexVec<CrateNum, Option<CrateNum>> { ) -> IndexVec<CrateNum, Option<CrateNum>> {
tcx.dep_graph.with_ignore(|| { tcx.dep_graph.with_ignore(|| {
let current_cnums = tcx let current_cnums = tcx
.all_crate_nums(LOCAL_CRATE) .all_crate_nums(())
.iter() .iter()
.map(|&cnum| { .map(|&cnum| {
let crate_name = tcx.original_crate_name(cnum).to_string(); let crate_name = tcx.original_crate_name(cnum).to_string();

View file

@ -4,14 +4,13 @@ use crate::ty::fast_reject;
use crate::ty::fold::TypeFoldable; use crate::ty::fold::TypeFoldable;
use crate::ty::{Ty, TyCtxt}; use crate::ty::{Ty, TyCtxt};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::def_id::DefId;
use rustc_hir::definitions::DefPathHash; use rustc_hir::definitions::DefPathHash;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_errors::ErrorReported; use rustc_errors::ErrorReported;
use rustc_macros::HashStable; use rustc_macros::HashStable;
use std::collections::BTreeMap;
/// A trait's definition with type information. /// A trait's definition with type information.
#[derive(HashStable)] #[derive(HashStable)]
@ -209,14 +208,6 @@ impl<'tcx> TyCtxt<'tcx> {
} }
} }
// Query provider for `all_local_trait_impls`.
pub(super) fn all_local_trait_impls<'tcx>(
tcx: TyCtxt<'tcx>,
krate: CrateNum,
) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
&tcx.hir_crate(krate).trait_impls
}
// Query provider for `trait_impls_of`. // Query provider for `trait_impls_of`.
pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> TraitImpls { pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> TraitImpls {
let mut impls = TraitImpls::default(); let mut impls = TraitImpls::default();

View file

@ -184,7 +184,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator}; use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
use rustc_errors::{ErrorReported, FatalError}; use rustc_errors::{ErrorReported, FatalError};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::GrowableBitSet; use rustc_index::bit_set::GrowableBitSet;
@ -322,7 +322,7 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
let mut roots = Vec::new(); let mut roots = Vec::new();
{ {
let entry_fn = tcx.entry_fn(LOCAL_CRATE); let entry_fn = tcx.entry_fn(());
debug!("collect_roots: entry_fn = {:?}", entry_fn); debug!("collect_roots: entry_fn = {:?}", entry_fn);
@ -468,7 +468,7 @@ fn shrunk_instance_name(
after = &s[positions().rev().nth(after).unwrap_or(0)..], after = &s[positions().rev().nth(after).unwrap_or(0)..],
); );
let path = tcx.output_filenames(LOCAL_CRATE).temp_path_ext("long-type.txt", None); let path = tcx.output_filenames(()).temp_path_ext("long-type.txt", None);
let written_to_path = std::fs::write(&path, s).ok().map(|_| path); let written_to_path = std::fs::write(&path, s).ok().map(|_| path);
(shrunk, written_to_path) (shrunk, written_to_path)

View file

@ -451,7 +451,9 @@ fn mono_item_visibility(
let is_generic = instance.substs.non_erasable_generics().next().is_some(); let is_generic = instance.substs.non_erasable_generics().next().is_some();
// Upstream `DefId` instances get different handling than local ones. // Upstream `DefId` instances get different handling than local ones.
if !def_id.is_local() { let def_id = if let Some(def_id) = def_id.as_local() {
def_id
} else {
return if export_generics && is_generic { return if export_generics && is_generic {
// If it is a upstream monomorphization and we export generics, we must make // If it is a upstream monomorphization and we export generics, we must make
// it available to downstream crates. // it available to downstream crates.
@ -460,7 +462,7 @@ fn mono_item_visibility(
} else { } else {
Visibility::Hidden Visibility::Hidden
}; };
} };
if is_generic { if is_generic {
if export_generics { if export_generics {
@ -470,7 +472,7 @@ fn mono_item_visibility(
} else { } else {
// This instance might be useful in a downstream crate. // This instance might be useful in a downstream crate.
*can_be_internalized = false; *can_be_internalized = false;
default_visibility(tcx, def_id, true) default_visibility(tcx, def_id.to_def_id(), true)
} }
} else { } else {
// We are not exporting generics or the definition is not reachable // We are not exporting generics or the definition is not reachable
@ -481,10 +483,10 @@ fn mono_item_visibility(
// If this isn't a generic function then we mark this a `Default` if // If this isn't a generic function then we mark this a `Default` if
// this is a reachable item, meaning that it's a symbol other crates may // this is a reachable item, meaning that it's a symbol other crates may
// access when they link to us. // access when they link to us.
if tcx.is_reachable_non_generic(def_id) { if tcx.is_reachable_non_generic(def_id.to_def_id()) {
*can_be_internalized = false; *can_be_internalized = false;
debug_assert!(!is_generic); debug_assert!(!is_generic);
return default_visibility(tcx, def_id, false); return default_visibility(tcx, def_id.to_def_id(), false);
} }
// If this isn't reachable then we're gonna tag this with `Hidden` // If this isn't reachable then we're gonna tag this with `Hidden`

View file

@ -97,7 +97,7 @@ mod merging;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync; use rustc_data_structures::sync;
use rustc_hir::def_id::{CrateNum, DefIdSet, LOCAL_CRATE}; use rustc_hir::def_id::DefIdSet;
use rustc_middle::mir::mono::MonoItem; use rustc_middle::mir::mono::MonoItem;
use rustc_middle::mir::mono::{CodegenUnit, Linkage}; use rustc_middle::mir::mono::{CodegenUnit, Linkage};
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
@ -311,10 +311,8 @@ where
fn collect_and_partition_mono_items<'tcx>( fn collect_and_partition_mono_items<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
cnum: CrateNum, (): (),
) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) { ) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
assert_eq!(cnum, LOCAL_CRATE);
let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items { let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items {
Some(ref s) => { Some(ref s) => {
let mode_string = s.to_lowercase(); let mode_string = s.to_lowercase();
@ -426,8 +424,8 @@ fn collect_and_partition_mono_items<'tcx>(
(tcx.arena.alloc(mono_items), codegen_units) (tcx.arena.alloc(mono_items), codegen_units)
} }
fn codegened_and_inlined_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx DefIdSet { fn codegened_and_inlined_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx DefIdSet {
let (items, cgus) = tcx.collect_and_partition_mono_items(cnum); let (items, cgus) = tcx.collect_and_partition_mono_items(());
let mut visited = DefIdSet::default(); let mut visited = DefIdSet::default();
let mut result = items.clone(); let mut result = items.clone();
@ -455,12 +453,12 @@ pub fn provide(providers: &mut Providers) {
providers.codegened_and_inlined_items = codegened_and_inlined_items; providers.codegened_and_inlined_items = codegened_and_inlined_items;
providers.is_codegened_item = |tcx, def_id| { providers.is_codegened_item = |tcx, def_id| {
let (all_mono_items, _) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); let (all_mono_items, _) = tcx.collect_and_partition_mono_items(());
all_mono_items.contains(&def_id) all_mono_items.contains(&def_id)
}; };
providers.codegen_unit = |tcx, name| { providers.codegen_unit = |tcx, name| {
let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); let (_, all) = tcx.collect_and_partition_mono_items(());
all.iter() all.iter()
.find(|cgu| cgu.name() == name) .find(|cgu| cgu.name() == name)
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name)) .unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))

View file

@ -3,7 +3,7 @@ use required_consts::RequiredConstsVisitor;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::steal::Steal; use rustc_data_structures::steal::Steal;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_middle::mir::visit::Visitor as _; use rustc_middle::mir::visit::Visitor as _;
@ -98,14 +98,13 @@ pub(crate) fn provide(providers: &mut Providers) {
} }
fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool { fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
tcx.mir_keys(def_id.krate).contains(&def_id.expect_local()) let def_id = def_id.expect_local();
tcx.mir_keys(()).contains(&def_id)
} }
/// Finds the full set of `DefId`s within the current crate that have /// Finds the full set of `DefId`s within the current crate that have
/// MIR associated with them. /// MIR associated with them.
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> FxHashSet<LocalDefId> { fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
assert_eq!(krate, LOCAL_CRATE);
let mut set = FxHashSet::default(); let mut set = FxHashSet::default();
// All body-owners have MIR associated with them. // All body-owners have MIR associated with them.

View file

@ -10,7 +10,7 @@ use super::spanview::write_mir_fn_spanview;
use crate::transform::MirSource; use crate::transform::MirSource;
use either::Either; use either::Either;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::DefId;
use rustc_index::vec::Idx; use rustc_index::vec::Idx;
use rustc_middle::mir::interpret::{ use rustc_middle::mir::interpret::{
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Pointer, read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Pointer,
@ -1020,6 +1020,6 @@ pub fn dump_mir_def_ids(tcx: TyCtxt<'_>, single: Option<DefId>) -> Vec<DefId> {
if let Some(i) = single { if let Some(i) = single {
vec![i] vec![i]
} else { } else {
tcx.mir_keys(LOCAL_CRATE).iter().map(|def_id| def_id.to_def_id()).collect() tcx.mir_keys(()).iter().map(|def_id| def_id.to_def_id()).collect()
} }
} }

View file

@ -5,7 +5,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res}; 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::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::{Node, PatKind, TyKind}; use rustc_hir::{Node, PatKind, TyKind};
@ -480,7 +480,7 @@ fn create_and_seed_worklist<'tcx>(
) )
.chain( .chain(
// Seed entry point // 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)) 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<'_>) { 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 krate = tcx.hir().krate();
let live_symbols = find_live(tcx, access_levels, krate); let live_symbols = find_live(tcx, access_levels, krate);
let mut visitor = DeadVisitor { tcx, live_symbols }; let mut visitor = DeadVisitor { tcx, live_symbols };

View file

@ -16,7 +16,7 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::Session; 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}; use rustc_span::symbol::{sym, Symbol};
struct DiagnosticItemCollector<'tcx> { 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 /// 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. // Initialize the collector.
let mut collector = DiagnosticItemCollector::new(tcx); 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. /// 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. // Initialize the collector.
let mut collector = FxHashMap::default(); 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) { pub fn provide(providers: &mut Providers) {
providers.diagnostic_items = |tcx, id| { providers.diagnostic_items = diagnostic_items;
assert_eq!(id, LOCAL_CRATE); providers.all_diagnostic_items = all_diagnostic_items;
collect(tcx)
};
providers.all_diagnostic_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
collect_all(tcx)
};
} }

View file

@ -1,6 +1,6 @@
use rustc_ast::entry::EntryPointType; use rustc_ast::entry::EntryPointType;
use rustc_errors::struct_span_err; 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::itemlikevisit::ItemLikeVisitor;
use rustc_hir::{ForeignItem, HirId, ImplItem, Item, ItemKind, TraitItem, CRATE_HIR_ID}; use rustc_hir::{ForeignItem, HirId, ImplItem, Item, ItemKind, TraitItem, CRATE_HIR_ID};
use rustc_middle::hir::map::Map; 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)> { fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
assert_eq!(cnum, LOCAL_CRATE);
let any_exe = tcx.sess.crate_types().iter().any(|ty| *ty == CrateType::Executable); let any_exe = tcx.sess.crate_types().iter().any(|ty| *ty == CrateType::Executable);
if !any_exe { if !any_exe {
// No need to find a main function. // No need to find a main function.
@ -227,10 +225,6 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
err.emit(); err.emit();
} }
pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(DefId, EntryFnType)> {
tcx.entry_fn(LOCAL_CRATE)
}
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
*providers = Providers { entry_fn, ..*providers }; *providers = Providers { entry_fn, ..*providers };
} }

View file

@ -15,7 +15,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir as hir; 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::itemlikevisit::ItemLikeVisitor;
use rustc_hir::lang_items::{extract, ITEM_REFS}; use rustc_hir::lang_items::{extract, ITEM_REFS};
use rustc_hir::{HirId, LangItem, LanguageItems, Target}; use rustc_hir::{HirId, LangItem, LanguageItems, Target};
@ -183,7 +183,7 @@ impl LanguageItemCollector<'tcx> {
} }
/// Traverses and collects all the lang items in all crates. /// 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. // Initialize the collector.
let mut collector = LanguageItemCollector::new(tcx); let mut collector = LanguageItemCollector::new(tcx);
@ -207,8 +207,5 @@ fn collect(tcx: TyCtxt<'_>) -> LanguageItems {
} }
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
providers.get_lang_items = |tcx, id| { providers.get_lang_items = get_lang_items;
assert_eq!(id, LOCAL_CRATE);
collect(tcx)
};
} }

View file

@ -6,7 +6,6 @@
use rustc_ast::{Attribute, MetaItem, MetaItemKind}; use rustc_ast::{Attribute, MetaItem, MetaItemKind};
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
use rustc_middle::middle::lib_features::LibFeatures; 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 mut collector = LibFeatureCollector::new(tcx);
let krate = tcx.hir().krate(); let krate = tcx.hir().krate();
for attr in krate.non_exported_macro_attrs { for attr in krate.non_exported_macro_attrs {
@ -138,8 +137,5 @@ fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
} }
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
providers.get_lib_features = |tcx, id| { providers.get_lib_features = get_lib_features;
assert_eq!(id, LOCAL_CRATE);
collect(tcx)
};
} }

View file

@ -8,8 +8,7 @@
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::Node; 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> { fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
debug_assert!(crate_num == LOCAL_CRATE); let access_levels = &tcx.privacy_access_levels(());
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
let any_library = let any_library =
tcx.sess.crate_types().iter().any(|ty| { tcx.sess.crate_types().iter().any(|ty| {

View file

@ -629,7 +629,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
// stable (assuming they have not inherited instability from their parent). // 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 = let is_staged_api =
tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api; tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api;
let mut staged_api = FxHashMap::default(); 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) { pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { check_mod_unstable_api_usage, ..*providers }; *providers = Providers { check_mod_unstable_api_usage, stability_index, ..*providers };
providers.stability_index = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
new_index(tcx)
};
} }
struct Checker<'tcx> { 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 /// 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. /// libraries, identify activated features that don't exist and error about them.
pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { 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] { if tcx.stability().staged_api[&LOCAL_CRATE] {
let krate = tcx.hir().krate(); let krate = tcx.hir().krate();

View file

@ -1,7 +1,7 @@
//! Used by `rustc` when compiling a plugin crate. //! Used by `rustc` when compiling a plugin crate.
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::LocalDefId;
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -31,25 +31,16 @@ impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> {
} }
/// Finds the function marked with `#[plugin_registrar]`, if any. /// Finds the function marked with `#[plugin_registrar]`, if any.
pub fn find_plugin_registrar(tcx: TyCtxt<'_>) -> Option<DefId> { fn plugin_registrar_fn(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
tcx.plugin_registrar_fn(LOCAL_CRATE)
}
fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
assert_eq!(cnum, LOCAL_CRATE);
let mut finder = RegistrarFinder { tcx, registrars: Vec::new() }; let mut finder = RegistrarFinder { tcx, registrars: Vec::new() };
tcx.hir().krate().visit_all_item_likes(&mut finder); tcx.hir().krate().visit_all_item_likes(&mut finder);
match finder.registrars.len() { let (def_id, span) = finder.registrars.pop()?;
0 => None,
1 => { if !finder.registrars.is_empty() {
let (def_id, _) = finder.registrars.pop().unwrap();
Some(def_id.to_def_id())
}
_ => {
let diagnostic = tcx.sess.diagnostic(); let diagnostic = tcx.sess.diagnostic();
let mut e = diagnostic.struct_err("multiple plugin registration functions found"); let mut e = diagnostic.struct_err("multiple plugin registration functions found");
e.span_note(span, "one is here");
for &(_, span) in &finder.registrars { for &(_, span) in &finder.registrars {
e.span_note(span, "one is here"); e.span_note(span, "one is here");
} }
@ -57,7 +48,8 @@ fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
diagnostic.abort_if_errors(); diagnostic.abort_if_errors();
unreachable!(); unreachable!();
} }
}
Some(def_id)
} }
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {

View file

@ -12,7 +12,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::intravisit::{self, DeepVisitor, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, DeepVisitor, NestedVisitorMap, Visitor};
use rustc_hir::{AssocItemKind, HirIdSet, Node, PatKind}; use rustc_hir::{AssocItemKind, HirIdSet, Node, PatKind};
use rustc_middle::bug; use rustc_middle::bug;
@ -2092,9 +2092,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
intravisit::walk_mod(&mut visitor, module, hir_id); intravisit::walk_mod(&mut visitor, module, hir_id);
} }
fn privacy_access_levels(tcx: TyCtxt<'_>, krate: CrateNum) -> &AccessLevels { fn privacy_access_levels(tcx: TyCtxt<'_>, (): ()) -> &AccessLevels {
assert_eq!(krate, LOCAL_CRATE);
// Build up a set of all exported items in the AST. This is a set of all // Build up a set of all exported items in the AST. This is a set of all
// items which are reachable from external crates based on visibility. // items which are reachable from external crates based on visibility.
let mut visitor = EmbargoVisitor { let mut visitor = EmbargoVisitor {
@ -2117,10 +2115,8 @@ fn privacy_access_levels(tcx: TyCtxt<'_>, krate: CrateNum) -> &AccessLevels {
tcx.arena.alloc(visitor.access_levels) tcx.arena.alloc(visitor.access_levels)
} }
fn check_private_in_public(tcx: TyCtxt<'_>, krate: CrateNum) { fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
assert_eq!(krate, LOCAL_CRATE); let access_levels = tcx.privacy_access_levels(());
let access_levels = tcx.privacy_access_levels(LOCAL_CRATE);
let krate = tcx.hir().krate(); let krate = tcx.hir().krate();

View file

@ -21,6 +21,16 @@ pub trait Key {
fn default_span(&self, tcx: TyCtxt<'_>) -> Span; fn default_span(&self, tcx: TyCtxt<'_>) -> Span;
} }
impl Key for () {
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
fn default_span(&self, _: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for ty::InstanceDef<'tcx> { impl<'tcx> Key for ty::InstanceDef<'tcx> {
fn query_crate(&self) -> CrateNum { fn query_crate(&self) -> CrateNum {
LOCAL_CRATE LOCAL_CRATE

View file

@ -95,7 +95,7 @@ impl<'tcx> SaveContext<'tcx> {
let sess = &self.tcx.sess; let sess = &self.tcx.sess;
// Save-analysis is emitted per whole session, not per each crate type // Save-analysis is emitted per whole session, not per each crate type
let crate_type = sess.crate_types()[0]; let crate_type = sess.crate_types()[0];
let outputs = &*self.tcx.output_filenames(LOCAL_CRATE); let outputs = &*self.tcx.output_filenames(());
if outputs.outputs.contains_key(&OutputType::Metadata) { if outputs.outputs.contains_key(&OutputType::Metadata) {
filename_for_metadata(sess, crate_name, outputs) filename_for_metadata(sess, crate_name, outputs)
@ -1000,7 +1000,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
// Privacy checking requires and is done after type checking; use a // Privacy checking requires and is done after type checking; use a
// fallback in case the access levels couldn't have been correctly computed. // fallback in case the access levels couldn't have been correctly computed.
let access_levels = match tcx.sess.compile_status() { let access_levels = match tcx.sess.compile_status() {
Ok(..) => tcx.privacy_access_levels(LOCAL_CRATE), Ok(..) => tcx.privacy_access_levels(()),
Err(..) => tcx.arena.alloc(AccessLevels::default()), Err(..) => tcx.arena.alloc(AccessLevels::default()),
}; };

View file

@ -165,11 +165,11 @@ fn compute_symbol_name(
// FIXME(eddyb) Precompute a custom symbol name based on attributes. // FIXME(eddyb) Precompute a custom symbol name based on attributes.
let is_foreign = if let Some(def_id) = def_id.as_local() { let is_foreign = if let Some(def_id) = def_id.as_local() {
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id.to_def_id()) { if tcx.plugin_registrar_fn(()) == Some(def_id) {
let disambiguator = tcx.sess.local_crate_disambiguator(); let disambiguator = tcx.sess.local_crate_disambiguator();
return tcx.sess.generate_plugin_registrar_symbol(disambiguator); return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
} }
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id.to_def_id()) { if tcx.proc_macro_decls_static(()) == Some(def_id) {
let disambiguator = tcx.sess.local_crate_disambiguator(); let disambiguator = tcx.sess.local_crate_disambiguator();
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator); return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
} }

View file

@ -14,7 +14,7 @@ use crate::infer::{self, InferCtxt, TyCtxtInferExt};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorReported}; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
use rustc_hir as hir; 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::intravisit::Visitor;
use rustc_hir::Node; use rustc_hir::Node;
use rustc_middle::mir::abstract_const::NotConstEvaluatable; use rustc_middle::mir::abstract_const::NotConstEvaluatable;
@ -1427,7 +1427,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
self.tcx.find_map_relevant_impl(trait_def_id, trait_ref.skip_binder().self_ty(), Some) 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 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 let traits_with_same_path: std::collections::BTreeSet<_> = all_traits
.iter() .iter()
.filter(|trait_def_id| **trait_def_id != trait_ref.def_id()) .filter(|trait_def_id| **trait_def_id != trait_ref.def_id())

View file

@ -6,7 +6,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Namespace, Res}; 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::intravisit;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{ExprKind, Node, QPath}; use rustc_hir::{ExprKind, Node, QPath};
@ -1440,11 +1440,11 @@ impl Ord for TraitInfo {
/// Retrieves all traits in this crate and any dependent crates. /// Retrieves all traits in this crate and any dependent crates.
pub fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> { pub fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> {
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. /// Computes all traits in this crate and any dependent crates.
fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> { fn compute_all_traits(tcx: TyCtxt<'_>, (): ()) -> &[DefId] {
use hir::itemlikevisit; use hir::itemlikevisit;
let mut traits = vec![]; let mut traits = vec![];
@ -1503,14 +1503,11 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
handle_external_res(tcx, &mut traits, &mut external_mods, Res::Def(DefKind::Mod, def_id)); 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) { pub fn provide(providers: &mut ty::query::Providers) {
providers.all_traits = |tcx, cnum| { providers.all_traits = compute_all_traits;
assert_eq!(cnum, LOCAL_CRATE);
&tcx.arena.alloc(compute_all_traits(tcx))[..]
}
} }
struct UsePlacementFinder<'tcx> { struct UsePlacementFinder<'tcx> {

View file

@ -105,7 +105,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{pluralize, struct_span_err, Applicability}; use rustc_errors::{pluralize, struct_span_err, Applicability};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::{HirIdMap, ImplicitSelfKind, Node}; use rustc_hir::{HirIdMap, ImplicitSelfKind, Node};
@ -1160,8 +1160,7 @@ impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> {
fn visit_foreign_item(&mut self, _: &'tcx hir::ForeignItem<'tcx>) {} fn visit_foreign_item(&mut self, _: &'tcx hir::ForeignItem<'tcx>) {}
} }
fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) { fn typeck_item_bodies(tcx: TyCtxt<'_>, (): ()) {
debug_assert!(crate_num == LOCAL_CRATE);
tcx.par_body_owners(|body_owner_def_id| { tcx.par_body_owners(|body_owner_def_id| {
tcx.ensure().typeck(body_owner_def_id); tcx.ensure().typeck(body_owner_def_id);
}); });

View file

@ -1,7 +1,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; 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_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::lint; use rustc_session::lint;
@ -77,7 +77,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
// can always suggest removing (no matter which edition we are // can always suggest removing (no matter which edition we are
// in). // in).
let unused_extern_crates: FxHashMap<LocalDefId, Span> = tcx let unused_extern_crates: FxHashMap<LocalDefId, Span> = tcx
.maybe_unused_extern_crates(LOCAL_CRATE) .maybe_unused_extern_crates(())
.iter() .iter()
.filter(|&&(def_id, _)| { .filter(|&&(def_id, _)| {
// The `def_id` here actually was calculated during resolution (at least // The `def_id` here actually was calculated during resolution (at least

View file

@ -9,16 +9,14 @@
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::{self, CrateInherentImpls, TyCtxt}; use rustc_middle::ty::{self, CrateInherentImpls, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
/// On-demand query: yields a map containing all types mapped to their inherent impls. /// On-demand query: yields a map containing all types mapped to their inherent impls.
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateInherentImpls { pub fn crate_inherent_impls(tcx: TyCtxt<'_>, (): ()) -> CrateInherentImpls {
assert_eq!(crate_num, LOCAL_CRATE);
let krate = tcx.hir().krate(); let krate = tcx.hir().krate();
let mut collect = InherentCollect { tcx, impls_map: Default::default() }; let mut collect = InherentCollect { tcx, impls_map: Default::default() };
krate.visit_all_item_likes(&mut collect); krate.visit_all_item_likes(&mut collect);
@ -27,9 +25,9 @@ pub fn crate_inherent_impls(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateInhere
/// On-demand query: yields a vector of the inherent impls for a specific type. /// On-demand query: yields a vector of the inherent impls for a specific type.
pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: DefId) -> &[DefId] { pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: DefId) -> &[DefId] {
assert!(ty_def_id.is_local()); let ty_def_id = ty_def_id.expect_local();
let crate_map = tcx.crate_inherent_impls(ty_def_id.krate); let crate_map = tcx.crate_inherent_impls(());
match crate_map.inherent_impls.get(&ty_def_id) { match crate_map.inherent_impls.get(&ty_def_id) {
Some(v) => &v[..], Some(v) => &v[..],
None => &[], None => &[],
@ -364,7 +362,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
impl InherentCollect<'tcx> { impl InherentCollect<'tcx> {
fn check_def_id(&mut self, item: &hir::Item<'_>, def_id: DefId) { fn check_def_id(&mut self, item: &hir::Item<'_>, def_id: DefId) {
if def_id.is_local() { if let Some(def_id) = def_id.as_local() {
// Add the implementation to the mapping from implementation to base // Add the implementation to the mapping from implementation to base
// type def ID, if there is a base type for this implementation and // type def ID, if there is a base type for this implementation and
// the implementation does not have any associated traits. // the implementation does not have any associated traits.

View file

@ -1,7 +1,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::DefId;
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::Symbol; use rustc_span::Symbol;
@ -9,8 +9,7 @@ use rustc_trait_selection::traits::{self, SkipLeakCheck};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, crate_num: CrateNum) { pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, (): ()) {
assert_eq!(crate_num, LOCAL_CRATE);
let krate = tcx.hir().krate(); let krate = tcx.hir().krate();
krate.visit_all_item_likes(&mut InherentOverlapChecker { tcx }); krate.visit_all_item_likes(&mut InherentOverlapChecker { tcx });
} }

View file

@ -6,7 +6,7 @@
// mappings. That mapping code resides here. // mappings. That mapping code resides here.
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
use rustc_span::Span; use rustc_span::Span;
@ -203,8 +203,8 @@ pub fn check_coherence(tcx: TyCtxt<'_>) {
tcx.sess.time("orphan_checking", || orphan::check(tcx)); tcx.sess.time("orphan_checking", || orphan::check(tcx));
// these queries are executed for side-effects (error reporting): // these queries are executed for side-effects (error reporting):
tcx.ensure().crate_inherent_impls(LOCAL_CRATE); tcx.ensure().crate_inherent_impls(());
tcx.ensure().crate_inherent_impls_overlap_check(LOCAL_CRATE); tcx.ensure().crate_inherent_impls_overlap_check(());
} }
/// Checks whether an impl overlaps with the automatic `impl Trait for dyn Trait`. /// Checks whether an impl overlaps with the automatic `impl Trait for dyn Trait`.

View file

@ -97,7 +97,7 @@ mod variance;
use rustc_errors::{struct_span_err, ErrorReported}; use rustc_errors::{struct_span_err, ErrorReported};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::DefId;
use rustc_hir::{Node, CRATE_HIR_ID}; use rustc_hir::{Node, CRATE_HIR_ID};
use rustc_infer::infer::{InferOk, TyCtxtInferExt}; use rustc_infer::infer::{InferOk, TyCtxtInferExt};
use rustc_infer::traits::TraitEngineExt as _; use rustc_infer::traits::TraitEngineExt as _;
@ -449,7 +449,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
} }
fn check_for_entry_fn(tcx: TyCtxt<'_>) { fn check_for_entry_fn(tcx: TyCtxt<'_>) {
match tcx.entry_fn(LOCAL_CRATE) { match tcx.entry_fn(()) {
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id), Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id), Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),
_ => {} _ => {}
@ -510,7 +510,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
} }
}); });
tcx.sess.time("item_bodies_checking", || tcx.typeck_item_bodies(LOCAL_CRATE)); tcx.sess.time("item_bodies_checking", || tcx.typeck_item_bodies(()));
check_unused::check_crate(tcx); check_unused::check_crate(tcx);
check_for_entry_fn(tcx); check_for_entry_fn(tcx);

View file

@ -1,6 +1,6 @@
use hir::Node; use hir::Node;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::DefId;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt}; use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
@ -23,7 +23,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
match tcx.hir().get(id) { match tcx.hir().get(id) {
Node::Item(item) => match item.kind { Node::Item(item) => match item.kind {
hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => { hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => {
let crate_map = tcx.inferred_outlives_crate(LOCAL_CRATE); let crate_map = tcx.inferred_outlives_crate(());
let predicates = crate_map.predicates.get(&item_def_id).copied().unwrap_or(&[]); let predicates = crate_map.predicates.get(&item_def_id).copied().unwrap_or(&[]);
@ -58,9 +58,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
} }
} }
fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredicatesMap<'_> { fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
assert_eq!(crate_num, LOCAL_CRATE);
// Compute a map from each struct/enum/union S to the **explicit** // Compute a map from each struct/enum/union S to the **explicit**
// outlives predicates (`T: 'a`, `'a: 'b`) that the user wrote. // outlives predicates (`T: 'a`, `'a: 'b`) that the user wrote.
// Typically there won't be many of these, except in older code where // Typically there won't be many of these, except in older code where

View file

@ -6,7 +6,7 @@
use hir::Node; use hir::Node;
use rustc_arena::DroplessArena; use rustc_arena::DroplessArena;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::DefId;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, CrateVariancesMap, TyCtxt}; use rustc_middle::ty::{self, CrateVariancesMap, TyCtxt};
@ -30,8 +30,7 @@ pub fn provide(providers: &mut Providers) {
*providers = Providers { variances_of, crate_variances, ..*providers }; *providers = Providers { variances_of, crate_variances, ..*providers };
} }
fn crate_variances(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateVariancesMap<'_> { fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
assert_eq!(crate_num, LOCAL_CRATE);
let arena = DroplessArena::default(); let arena = DroplessArena::default();
let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &arena); let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &arena);
let constraints_cx = constraints::add_constraints_from_crate(terms_cx); let constraints_cx = constraints::add_constraints_from_crate(terms_cx);
@ -79,6 +78,6 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
// Everything else must be inferred. // Everything else must be inferred.
let crate_map = tcx.crate_variances(LOCAL_CRATE); let crate_map = tcx.crate_variances(());
crate_map.variances.get(&item_def_id).copied().unwrap_or(&[]) crate_map.variances.get(&item_def_id).copied().unwrap_or(&[])
} }

View file

@ -1,6 +1,5 @@
use crate::rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use crate::rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_infer::infer::{InferOk, TyCtxtInferExt}; use rustc_infer::infer::{InferOk, TyCtxtInferExt};
use rustc_infer::traits; use rustc_infer::traits;
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
@ -20,7 +19,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
debug!("get_blanket_impls({:?})", ty); debug!("get_blanket_impls({:?})", ty);
let mut impls = Vec::new(); 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) if !self.cx.cache.access_levels.is_public(trait_def_id)
|| self.cx.generated_synthetics.get(&(ty, trait_def_id)).is_some() || self.cx.generated_synthetics.get(&(ty, trait_def_id)).is_some()
{ {

View file

@ -6,7 +6,7 @@ use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_errors::json::JsonEmitter; use rustc_errors::json::JsonEmitter;
use rustc_feature::UnstableFeatures; use rustc_feature::UnstableFeatures;
use rustc_hir::def::Res; 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::HirId;
use rustc_hir::{ use rustc_hir::{
intravisit::{self, NestedVisitorMap, Visitor}, intravisit::{self, NestedVisitorMap, Visitor},
@ -348,7 +348,7 @@ crate fn run_global_ctxt(
}); });
rustc_passes::stability::check_unused_or_stable_features(tcx); rustc_passes::stability::check_unused_or_stable_features(tcx);
let access_levels = tcx.privacy_access_levels(LOCAL_CRATE); let access_levels = tcx.privacy_access_levels(());
// Convert from a HirId set to a DefId set since we don't always have easy access // Convert from a HirId set to a DefId set since we don't always have easy access
// to the map from defid -> hirid // to the map from defid -> hirid
let access_levels = AccessLevels { let access_levels = AccessLevels {
@ -371,7 +371,7 @@ crate fn run_global_ctxt(
impl_trait_bounds: Default::default(), impl_trait_bounds: Default::default(),
generated_synthetics: Default::default(), generated_synthetics: Default::default(),
auto_traits: tcx auto_traits: tcx
.all_traits(LOCAL_CRATE) .all_traits(())
.iter() .iter()
.cloned() .cloned()
.filter(|trait_def_id| tcx.trait_is_auto(*trait_def_id)) .filter(|trait_def_id| tcx.trait_is_auto(*trait_def_id))

View file

@ -1208,13 +1208,11 @@ impl LinkCollector<'_, '_> {
item.def_id.expect_real().as_local().map(|src_id| (src_id, dst_id)) item.def_id.expect_real().as_local().map(|src_id| (src_id, dst_id))
}) })
{ {
use rustc_hir::def_id::LOCAL_CRATE;
let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id); let hir_src = self.cx.tcx.hir().local_def_id_to_hir_id(src_id);
let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id); let hir_dst = self.cx.tcx.hir().local_def_id_to_hir_id(dst_id);
if self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_src) if self.cx.tcx.privacy_access_levels(()).is_exported(hir_src)
&& !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_dst) && !self.cx.tcx.privacy_access_levels(()).is_exported(hir_dst)
{ {
privacy_error(self.cx, &diag_info, &path_str); privacy_error(self.cx, &diag_info, &path_str);
} }

View file

@ -4,7 +4,7 @@ use crate::core::DocContext;
use crate::fold::DocFolder; use crate::fold::DocFolder;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; 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_middle::ty::DefIdTree;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -56,7 +56,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
// `tcx.crates()` doesn't include the local crate, and `tcx.all_trait_implementations` // `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 // doesn't work with it anyway, so pull them from the HIR map instead
let mut extra_attrs = Vec::new(); 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) { for &impl_did in cx.tcx.hir().trait_impls(trait_did) {
let impl_did = impl_did.to_def_id(); let impl_did = impl_did.to_def_id();
cx.tcx.sess.prof.generic_activity("build_local_trait_impl").run(|| { cx.tcx.sess.prof.generic_activity("build_local_trait_impl").run(|| {

View file

@ -6,9 +6,9 @@
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![allow(dead_code)] #![allow(dead_code)]
#![allow(unused_variables)] #![allow(unused_variables)]
#![rustc_if_this_changed(hir_crate)]
fn main() {} fn main() {}
#[rustc_if_this_changed]
struct Foo<T> { struct Foo<T> {
f: T, f: T,
} }

View file

@ -14,16 +14,16 @@ LL | #[plugin_registrar]
error: multiple plugin registration functions found error: multiple plugin registration functions found
| |
note: one is here
--> $DIR/multiple-plugin-registrars.rs:7:1
|
LL | pub fn one() {}
| ^^^^^^^^^^^^^^^
note: one is here note: one is here
--> $DIR/multiple-plugin-registrars.rs:10:1 --> $DIR/multiple-plugin-registrars.rs:10:1
| |
LL | pub fn two() {} LL | pub fn two() {}
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
note: one is here
--> $DIR/multiple-plugin-registrars.rs:7:1
|
LL | pub fn one() {}
| ^^^^^^^^^^^^^^^
error: aborting due to previous error; 2 warnings emitted error: aborting due to previous error; 2 warnings emitted

View file

@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{def_id::LOCAL_CRATE, source_map::Span}; use rustc_span::{source_map::Span};
declare_clippy_lint! { declare_clippy_lint! {
/// **What it does:** Checks for deriving `Hash` but implementing `PartialEq` /// **What it does:** Checks for deriving `Hash` but implementing `PartialEq`
@ -312,7 +312,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &T
if ty_subs.non_erasable_generics().next().is_some() { if ty_subs.non_erasable_generics().next().is_some() {
let has_copy_impl = cx let has_copy_impl = cx
.tcx .tcx
.all_local_trait_impls(LOCAL_CRATE) .all_local_trait_impls(())
.get(&copy_id) .get(&copy_id)
.map_or(false, |impls| { .map_or(false, |impls| {
impls impls

View file

@ -3,7 +3,7 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::in_macro; use clippy_utils::in_macro;
use rustc_hir::def_id::DefIdMap; use rustc_hir::def_id::DefIdMap;
use rustc_hir::{def_id, Crate, Impl, Item, ItemKind}; use rustc_hir::{Crate, Impl, Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::Span; use rustc_span::Span;
@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) { fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) {
if !krate.items.is_empty() { if !krate.items.is_empty() {
// Retrieve all inherent implementations from the crate, grouped by type // Retrieve all inherent implementations from the crate, grouped by type
for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() { for impls in cx.tcx.crate_inherent_impls(()).inherent_impls.values() {
// Filter out implementations that have generic params (type or lifetime) // Filter out implementations that have generic params (type or lifetime)
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def)); let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
if let Some(initial_span) = impl_spans.next() { if let Some(initial_span) = impl_spans.next() {

View file

@ -60,7 +60,7 @@ use rustc_ast::ast::{self, Attribute, BorrowKind, LitKind};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor};
use rustc_hir::LangItem::{ResultErr, ResultOk}; use rustc_hir::LangItem::{ResultErr, ResultOk};
use rustc_hir::{ use rustc_hir::{
@ -677,7 +677,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option<Vec
/// Returns `true` if the provided `def_id` is an entrypoint to a program. /// Returns `true` if the provided `def_id` is an entrypoint to a program.
pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool { pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool {
cx.tcx cx.tcx
.entry_fn(LOCAL_CRATE) .entry_fn(())
.map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id) .map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id)
} }