1
Fork 0

Auto merge of #71292 - marmeladema:queries-local-def-id, r=eddyb

Convert more queries to use `LocalDefId`

This PR is based on commits in https://github.com/rust-lang/rust/pull/71215 and should partially solve #70853
This commit is contained in:
bors 2020-04-28 05:01:27 +00:00
commit fb5615a477
43 changed files with 288 additions and 239 deletions

View file

@ -290,7 +290,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
spflags |= DISPFlags::SPFlagOptimized; spflags |= DISPFlags::SPFlagOptimized;
} }
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) { if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
if id == def_id { if id.to_def_id() == def_id {
spflags |= DISPFlags::SPFlagMainSubprogram; spflags |= DISPFlags::SPFlagMainSubprogram;
} }
} }

View file

@ -30,7 +30,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::profiling::print_time_passes_entry; use rustc_data_structures::profiling::print_time_passes_entry;
use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator}; use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
use rustc_hir::lang_items::StartFnLangItem; use rustc_hir::lang_items::StartFnLangItem;
use rustc_index::vec::Idx; use rustc_index::vec::Idx;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
@ -397,7 +397,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
None => return None, None => return None,
}; };
let instance = Instance::mono(cx.tcx(), main_def_id); let instance = Instance::mono(cx.tcx(), main_def_id.to_def_id());
if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) { if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
// We want to create the wrapper in the same codegen unit as Rust's main // We want to create the wrapper in the same codegen unit as Rust's main
@ -416,7 +416,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx, cx: &'a Bx::CodegenCx,
sp: Span, sp: Span,
rust_main: Bx::Value, rust_main: Bx::Value,
rust_main_def_id: DefId, rust_main_def_id: LocalDefId,
use_start_lang_item: bool, use_start_lang_item: bool,
) -> Bx::Function { ) -> Bx::Function {
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`, // The entry function is either `int main(void)` or `int main(int argc, char **argv)`,

View file

@ -835,7 +835,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
}); });
sess.time("MIR_borrow_checking", || { sess.time("MIR_borrow_checking", || {
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id.to_def_id())); tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
}); });
sess.time("dumping_chalk_like_clauses", || { sess.time("dumping_chalk_like_clauses", || {

View file

@ -293,7 +293,7 @@ impl<'tcx> Queries<'tcx> {
_ => return, _ => return,
}; };
let attrs = &*tcx.get_attrs(def_id); let attrs = &*tcx.get_attrs(def_id.to_def_id());
let attrs = attrs.iter().filter(|attr| attr.check_name(sym::rustc_error)); let attrs = attrs.iter().filter(|attr| attr.check_name(sym::rustc_error));
for attr in attrs { for attr in attrs {
match attr.meta_item_list() { match attr.meta_item_list() {

View file

@ -56,7 +56,7 @@ mod unused;
use rustc_ast::ast; use rustc_ast::ast;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::LocalDefId;
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::lint::builtin::{ use rustc_session::lint::builtin::{
@ -90,12 +90,8 @@ pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers { lint_mod, ..*providers }; *providers = Providers { lint_mod, ..*providers };
} }
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: DefId) { fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
late::late_lint_mod( late::late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
tcx,
module_def_id.expect_local(),
BuiltinCombinedModuleLateLintPass::new(),
);
} }
macro_rules! pre_expansion_lint_passes { macro_rules! pre_expansion_lint_passes {

View file

@ -5,12 +5,11 @@ use log::{debug, trace};
use rustc_ast::ast::{self, Ident}; use rustc_ast::ast::{self, Ident};
use rustc_ast::attr; use rustc_ast::attr;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::stable_hasher::StableHasher;
use rustc_data_structures::sync::{join, Lrc}; use rustc_data_structures::sync::{join, Lrc};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::CtorKind; use rustc_hir::def::CtorKind;
use rustc_hir::def_id::DefIdSet;
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::definitions::DefPathTable; use rustc_hir::definitions::DefPathTable;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
@ -644,8 +643,8 @@ impl EncodeContext<'tcx> {
self.encode_generics(def_id); self.encode_generics(def_id);
self.encode_explicit_predicates(def_id); self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id); self.encode_inferred_outlives(def_id);
self.encode_optimized_mir(def_id); self.encode_optimized_mir(def_id.expect_local());
self.encode_promoted_mir(def_id); self.encode_promoted_mir(def_id.expect_local());
} }
fn encode_enum_variant_ctor(&mut self, def: &ty::AdtDef, index: VariantIdx) { fn encode_enum_variant_ctor(&mut self, def: &ty::AdtDef, index: VariantIdx) {
@ -683,8 +682,8 @@ impl EncodeContext<'tcx> {
self.encode_generics(def_id); self.encode_generics(def_id);
self.encode_explicit_predicates(def_id); self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id); self.encode_inferred_outlives(def_id);
self.encode_optimized_mir(def_id); self.encode_optimized_mir(def_id.expect_local());
self.encode_promoted_mir(def_id); self.encode_promoted_mir(def_id.expect_local());
} }
fn encode_info_for_mod( fn encode_info_for_mod(
@ -786,8 +785,8 @@ impl EncodeContext<'tcx> {
self.encode_generics(def_id); self.encode_generics(def_id);
self.encode_explicit_predicates(def_id); self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id); self.encode_inferred_outlives(def_id);
self.encode_optimized_mir(def_id); self.encode_optimized_mir(def_id.expect_local());
self.encode_promoted_mir(def_id); self.encode_promoted_mir(def_id.expect_local());
} }
fn encode_generics(&mut self, def_id: DefId) { fn encode_generics(&mut self, def_id: DefId) {
@ -896,8 +895,8 @@ impl EncodeContext<'tcx> {
self.encode_inferred_outlives(def_id); self.encode_inferred_outlives(def_id);
// This should be kept in sync with `PrefetchVisitor.visit_trait_item`. // This should be kept in sync with `PrefetchVisitor.visit_trait_item`.
self.encode_optimized_mir(def_id); self.encode_optimized_mir(def_id.expect_local());
self.encode_promoted_mir(def_id); self.encode_promoted_mir(def_id.expect_local());
} }
fn metadata_output_only(&self) -> bool { fn metadata_output_only(&self) -> bool {
@ -985,8 +984,8 @@ impl EncodeContext<'tcx> {
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => false, hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => false,
}; };
if mir { if mir {
self.encode_optimized_mir(def_id); self.encode_optimized_mir(def_id.expect_local());
self.encode_promoted_mir(def_id); self.encode_promoted_mir(def_id.expect_local());
} }
} }
@ -1004,17 +1003,17 @@ impl EncodeContext<'tcx> {
self.lazy(param_names.iter().map(|ident| ident.name)) self.lazy(param_names.iter().map(|ident| ident.name))
} }
fn encode_optimized_mir(&mut self, def_id: DefId) { fn encode_optimized_mir(&mut self, def_id: LocalDefId) {
debug!("EntryBuilder::encode_mir({:?})", def_id); debug!("EntryBuilder::encode_mir({:?})", def_id);
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) { if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
record!(self.tables.mir[def_id] <- self.tcx.optimized_mir(def_id)); record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
} }
} }
fn encode_promoted_mir(&mut self, def_id: DefId) { fn encode_promoted_mir(&mut self, def_id: LocalDefId) {
debug!("EncodeContext::encode_promoted_mir({:?})", def_id); debug!("EncodeContext::encode_promoted_mir({:?})", def_id);
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) { if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
record!(self.tables.promoted_mir[def_id] <- self.tcx.promoted_mir(def_id)); record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(def_id));
} }
} }
@ -1282,8 +1281,8 @@ impl EncodeContext<'tcx> {
_ => false, _ => false,
}; };
if mir { if mir {
self.encode_optimized_mir(def_id); self.encode_optimized_mir(def_id.expect_local());
self.encode_promoted_mir(def_id); self.encode_promoted_mir(def_id.expect_local());
} }
} }
@ -1316,8 +1315,7 @@ impl EncodeContext<'tcx> {
let hir_id = self.tcx.hir().as_local_hir_id(def_id); let hir_id = self.tcx.hir().as_local_hir_id(def_id);
let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id); let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id);
let def_id = def_id.to_def_id(); record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind {
record!(self.tables.kind[def_id] <- match ty.kind {
ty::Generator(..) => { ty::Generator(..) => {
let data = self.tcx.generator_kind(def_id).unwrap(); let data = self.tcx.generator_kind(def_id).unwrap();
EntryKind::Generator(data) EntryKind::Generator(data)
@ -1327,14 +1325,14 @@ impl EncodeContext<'tcx> {
_ => bug!("closure that is neither generator nor closure"), _ => bug!("closure that is neither generator nor closure"),
}); });
record!(self.tables.visibility[def_id] <- ty::Visibility::Public); record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]); record!(self.tables.attributes[def_id.to_def_id()] <- &self.tcx.get_attrs(def_id.to_def_id())[..]);
self.encode_item_type(def_id); self.encode_item_type(def_id.to_def_id());
if let ty::Closure(def_id, substs) = ty.kind { if let ty::Closure(def_id, substs) = ty.kind {
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig()); record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
} }
self.encode_generics(def_id); self.encode_generics(def_id.to_def_id());
self.encode_optimized_mir(def_id); self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id); self.encode_promoted_mir(def_id);
} }
@ -1344,16 +1342,15 @@ impl EncodeContext<'tcx> {
let id = self.tcx.hir().as_local_hir_id(def_id); let id = self.tcx.hir().as_local_hir_id(def_id);
let body_id = self.tcx.hir().body_owned_by(id); let body_id = self.tcx.hir().body_owned_by(id);
let const_data = self.encode_rendered_const_for_body(body_id); let const_data = self.encode_rendered_const_for_body(body_id);
let def_id = def_id.to_def_id();
let qualifs = self.tcx.mir_const_qualif(def_id); let qualifs = self.tcx.mir_const_qualif(def_id);
record!(self.tables.kind[def_id] <- EntryKind::Const(qualifs, const_data)); record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::Const(qualifs, const_data));
record!(self.tables.visibility[def_id] <- ty::Visibility::Public); record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id)); record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
self.encode_item_type(def_id); self.encode_item_type(def_id.to_def_id());
self.encode_generics(def_id); self.encode_generics(def_id.to_def_id());
self.encode_explicit_predicates(def_id); self.encode_explicit_predicates(def_id.to_def_id());
self.encode_inferred_outlives(def_id); self.encode_inferred_outlives(def_id.to_def_id());
self.encode_optimized_mir(def_id); self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id); self.encode_promoted_mir(def_id);
} }
@ -1726,12 +1723,11 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
/// Only a subset of the queries are actually prefetched to keep this code smaller. /// Only a subset of the queries are actually prefetched to keep this code smaller.
struct PrefetchVisitor<'tcx> { struct PrefetchVisitor<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
mir_keys: &'tcx DefIdSet, mir_keys: &'tcx FxHashSet<LocalDefId>,
} }
impl<'tcx> PrefetchVisitor<'tcx> { impl<'tcx> PrefetchVisitor<'tcx> {
fn prefetch_mir(&self, def_id: LocalDefId) { fn prefetch_mir(&self, def_id: LocalDefId) {
let def_id = def_id.to_def_id();
if self.mir_keys.contains(&def_id) { if self.mir_keys.contains(&def_id) {
self.tcx.optimized_mir(def_id); self.tcx.optimized_mir(def_id);
self.tcx.promoted_mir(def_id); self.tcx.promoted_mir(def_id);

View file

@ -34,7 +34,8 @@ macro_rules! arena_types {
rustc_hir::def_id::DefId, rustc_hir::def_id::DefId,
rustc_middle::ty::subst::SubstsRef<$tcx> rustc_middle::ty::subst::SubstsRef<$tcx>
)>, )>,
[few, decode] mir_keys: rustc_hir::def_id::DefIdSet, [few, decode] collect_and_partition_mono_items: rustc_hir::def_id::DefIdSet,
[few, decode] mir_keys: rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>,
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph, [decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
[] region_scope_tree: rustc_middle::middle::region::ScopeTree, [] region_scope_tree: rustc_middle::middle::region::ScopeTree,
[] item_local_set: rustc_hir::ItemLocalSet, [] item_local_set: rustc_hir::ItemLocalSet,

View file

@ -7,7 +7,7 @@ use rustc_data_structures::base_n;
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::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_session::config::OptLevel; use rustc_session::config::OptLevel;
use rustc_span::source_map::Span; use rustc_span::source_map::Span;
@ -95,7 +95,7 @@ impl<'tcx> MonoItem<'tcx> {
// linkage, then we'll be creating a globally shared version. // linkage, then we'll be creating a globally shared version.
if self.explicit_linkage(tcx).is_some() if self.explicit_linkage(tcx).is_some()
|| !instance.def.generates_cgu_internal_copy(tcx) || !instance.def.generates_cgu_internal_copy(tcx)
|| Some(instance.def_id()) == entry_def_id || Some(instance.def_id()) == entry_def_id.map(LocalDefId::to_def_id)
{ {
return InstantiationMode::GloballyShared { may_conflict: false }; return InstantiationMode::GloballyShared { may_conflict: false };
} }

View file

@ -156,7 +156,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) -> &'tcx DefIdSet { query mir_keys(_: CrateNum) -> &'tcx FxHashSet<LocalDefId> {
desc { "getting a list of all mir_keys" } desc { "getting a list of all mir_keys" }
} }
@ -170,7 +170,7 @@ rustc_queries! {
/// Fetch the MIR for a given `DefId` right after it's built - this includes /// Fetch the MIR for a given `DefId` right after it's built - this includes
/// unreachable code. /// unreachable code.
query mir_built(_: DefId) -> &'tcx Steal<mir::Body<'tcx>> { query mir_built(_: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
desc { "building MIR for" } desc { "building MIR for" }
} }
@ -182,12 +182,13 @@ rustc_queries! {
no_hash no_hash
} }
query mir_validated(_: DefId) -> query mir_validated(key: LocalDefId) ->
( (
&'tcx Steal<mir::Body<'tcx>>, &'tcx Steal<mir::Body<'tcx>>,
&'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>> &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
) { ) {
no_hash no_hash
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
} }
/// MIR after our optimization passes have run. This is MIR that is ready /// MIR after our optimization passes have run. This is MIR that is ready
@ -275,9 +276,9 @@ rustc_queries! {
/// To avoid cycles within the predicates of a single item we compute /// To avoid cycles within the predicates of a single item we compute
/// per-type-parameter predicates for resolving `T::AssocTy`. /// per-type-parameter predicates for resolving `T::AssocTy`.
query type_param_predicates(key: (DefId, DefId)) -> ty::GenericPredicates<'tcx> { query type_param_predicates(key: (DefId, LocalDefId)) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing the bounds for type parameter `{}`", { desc { |tcx| "computing the bounds for type parameter `{}`", {
let id = tcx.hir().as_local_hir_id(key.1.expect_local()); let id = tcx.hir().as_local_hir_id(key.1);
tcx.hir().ty_param_name(id) tcx.hir().ty_param_name(id)
}} }}
} }
@ -389,9 +390,9 @@ rustc_queries! {
TypeChecking { TypeChecking {
/// The result of unsafety-checking this `DefId`. /// The result of unsafety-checking this `DefId`.
query unsafety_check_result(key: DefId) -> mir::UnsafetyCheckResult { query unsafety_check_result(key: LocalDefId) -> mir::UnsafetyCheckResult {
desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key) } desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if { key.is_local() } cache_on_disk_if { true }
} }
/// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
@ -402,8 +403,8 @@ rustc_queries! {
} }
Other { Other {
query lint_mod(key: DefId) -> () { query lint_mod(key: LocalDefId) -> () {
desc { |tcx| "linting {}", describe_as_module(key, tcx) } desc { |tcx| "linting {}", describe_as_module(key.to_def_id(), tcx) }
} }
/// Checks the attributes in the module. /// Checks the attributes in the module.
@ -429,8 +430,8 @@ rustc_queries! {
desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) } desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
} }
query check_mod_privacy(key: DefId) -> () { query check_mod_privacy(key: LocalDefId) -> () {
desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) } desc { |tcx| "checking privacy in {}", describe_as_module(key.to_def_id(), tcx) }
} }
query check_mod_intrinsics(key: DefId) -> () { query check_mod_intrinsics(key: DefId) -> () {
@ -459,12 +460,13 @@ rustc_queries! {
desc { "type-checking all item bodies" } desc { "type-checking all item bodies" }
} }
query typeck_tables_of(key: DefId) -> &'tcx ty::TypeckTables<'tcx> { query typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> {
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) } desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if { key.is_local() } cache_on_disk_if { true }
} }
query diagnostic_only_typeck_tables_of(key: DefId) -> &'tcx ty::TypeckTables<'tcx> { query diagnostic_only_typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> {
cache_on_disk_if { key.is_local() } desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if { true }
load_cached(tcx, id) { load_cached(tcx, id) {
let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
.queries.on_disk_cache .queries.on_disk_cache
@ -476,8 +478,9 @@ rustc_queries! {
} }
Other { Other {
query used_trait_imports(key: DefId) -> &'tcx DefIdSet { query used_trait_imports(key: LocalDefId) -> &'tcx DefIdSet {
cache_on_disk_if { key.is_local() } desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if { true }
} }
} }
@ -492,12 +495,11 @@ rustc_queries! {
BorrowChecking { BorrowChecking {
/// Borrow-checks the function body. If this is a closure, returns /// Borrow-checks the function body. If this is a closure, returns
/// additional requirements that the closure's creator must verify. /// additional requirements that the closure's creator must verify.
query mir_borrowck(key: DefId) -> &'tcx mir::BorrowCheckResult<'tcx> { query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key) } desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if(tcx, opt_result) { cache_on_disk_if(tcx, opt_result) {
key.is_local() tcx.is_closure(key.to_def_id())
&& (tcx.is_closure(key) || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
|| opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty()))
} }
} }
} }
@ -802,9 +804,15 @@ rustc_queries! {
TypeChecking { TypeChecking {
query impl_defaultness(_: DefId) -> hir::Defaultness {} query impl_defaultness(_: DefId) -> hir::Defaultness {}
query check_item_well_formed(_: DefId) -> () {} query check_item_well_formed(key: LocalDefId) -> () {
query check_trait_item_well_formed(_: DefId) -> () {} desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
query check_impl_item_well_formed(_: DefId) -> () {} }
query check_trait_item_well_formed(key: LocalDefId) -> () {
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
}
query check_impl_item_well_formed(key: LocalDefId) -> () {
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
}
} }
Linking { Linking {
@ -878,7 +886,7 @@ 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(_: CrateNum) -> Option<(LocalDefId, 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(_: CrateNum) -> Option<DefId> {
@ -1028,17 +1036,19 @@ rustc_queries! {
query upvars(_: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> { query upvars(_: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
eval_always eval_always
} }
query maybe_unused_trait_import(_: DefId) -> bool { query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
eval_always eval_always
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(_: CrateNum)
-> &'tcx [(DefId, Span)] { -> &'tcx [(DefId, Span)] {
eval_always eval_always
desc { "looking up all possibly unused extern crates" } desc { "looking up all possibly unused extern crates" }
} }
query names_imported_by_glob_use(_: DefId) query names_imported_by_glob_use(def_id: LocalDefId)
-> &'tcx FxHashSet<ast::Name> { -> &'tcx FxHashSet<ast::Name> {
eval_always eval_always
desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
} }
query stability_index(_: CrateNum) -> &'tcx stability::Index<'tcx> { query stability_index(_: CrateNum) -> &'tcx stability::Index<'tcx> {

View file

@ -945,11 +945,11 @@ pub struct GlobalCtxt<'tcx> {
pub queries: query::Queries<'tcx>, pub queries: query::Queries<'tcx>,
maybe_unused_trait_imports: FxHashSet<DefId>, maybe_unused_trait_imports: FxHashSet<LocalDefId>,
maybe_unused_extern_crates: Vec<(DefId, Span)>, maybe_unused_extern_crates: Vec<(DefId, Span)>,
/// A map of glob use to a set of names it actually imports. Currently only /// A map of glob use to a set of names it actually imports. Currently only
/// used in save-analysis. /// used in save-analysis.
glob_map: FxHashMap<DefId, FxHashSet<ast::Name>>, glob_map: FxHashMap<LocalDefId, FxHashSet<ast::Name>>,
/// Extern prelude entries. The value is `true` if the entry was introduced /// Extern prelude entries. The value is `true` if the entry was introduced
/// via `extern crate` item and not `--extern` option or compiler built-in. /// via `extern crate` item and not `--extern` option or compiler built-in.
pub extern_prelude: FxHashMap<ast::Name, bool>, pub extern_prelude: FxHashMap<ast::Name, bool>,
@ -1165,7 +1165,7 @@ impl<'tcx> TyCtxt<'tcx> {
maybe_unused_trait_imports: resolutions maybe_unused_trait_imports: resolutions
.maybe_unused_trait_imports .maybe_unused_trait_imports
.into_iter() .into_iter()
.map(|id| definitions.local_def_id(id).to_def_id()) .map(|id| definitions.local_def_id(id))
.collect(), .collect(),
maybe_unused_extern_crates: resolutions maybe_unused_extern_crates: resolutions
.maybe_unused_extern_crates .maybe_unused_extern_crates
@ -1175,7 +1175,7 @@ impl<'tcx> TyCtxt<'tcx> {
glob_map: resolutions glob_map: resolutions
.glob_map .glob_map
.into_iter() .into_iter()
.map(|(id, names)| (definitions.local_def_id(id).to_def_id(), names)) .map(|(id, names)| (definitions.local_def_id(id), names))
.collect(), .collect(),
extern_prelude: resolutions.extern_prelude, extern_prelude: resolutions.extern_prelude,
untracked_crate: krate, untracked_crate: krate,
@ -2716,10 +2716,8 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(cnum, LOCAL_CRATE); assert_eq!(cnum, LOCAL_CRATE);
&tcx.maybe_unused_extern_crates[..] &tcx.maybe_unused_extern_crates[..]
}; };
providers.names_imported_by_glob_use = |tcx, id| { providers.names_imported_by_glob_use =
assert_eq!(id.krate, LOCAL_CRATE); |tcx, id| tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default());
tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default())
};
providers.lookup_stability = |tcx, id| { providers.lookup_stability = |tcx, id| {
let id = tcx.hir().local_def_id_to_hir_id(id.expect_local()); let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());

View file

@ -2637,7 +2637,7 @@ pub enum ImplOverlapKind {
impl<'tcx> TyCtxt<'tcx> { impl<'tcx> TyCtxt<'tcx> {
pub fn body_tables(self, body: hir::BodyId) -> &'tcx TypeckTables<'tcx> { pub fn body_tables(self, body: hir::BodyId) -> &'tcx TypeckTables<'tcx> {
self.typeck_tables_of(self.hir().body_owner_def_id(body).to_def_id()) self.typeck_tables_of(self.hir().body_owner_def_id(body))
} }
/// Returns an iterator of the `DefId`s for all body-owners in this /// Returns an iterator of the `DefId`s for all body-owners in this

View file

@ -117,6 +117,17 @@ impl Key for (DefId, DefId) {
} }
} }
impl Key for (DefId, LocalDefId) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0.krate
}
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.1.default_span(tcx)
}
}
impl Key for (CrateNum, DefId) { impl Key for (CrateNum, DefId) {
type CacheSelector = DefaultCacheSelector; type CacheSelector = DefaultCacheSelector;

View file

@ -191,7 +191,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
.ty; .ty;
let needs_note = match ty.kind { let needs_note = match ty.kind {
ty::Closure(id, _) => { ty::Closure(id, _) => {
let tables = self.infcx.tcx.typeck_tables_of(id); let tables = self.infcx.tcx.typeck_tables_of(id.expect_local());
let hir_id = self.infcx.tcx.hir().as_local_hir_id(id.expect_local()); let hir_id = self.infcx.tcx.hir().as_local_hir_id(id.expect_local());
tables.closure_kind_origins().get(hir_id).is_none() tables.closure_kind_origins().get(hir_id).is_none()
@ -880,7 +880,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
match &self match &self
.infcx .infcx
.tcx .tcx
.typeck_tables_of(self.mir_def_id) .typeck_tables_of(def_id)
.node_type(fn_hir_id) .node_type(fn_hir_id)
.kind .kind
{ {

View file

@ -97,7 +97,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
debug!("add_moved_or_invoked_closure_note: closure={:?}", closure); debug!("add_moved_or_invoked_closure_note: closure={:?}", closure);
if let ty::Closure(did, _) = self.body.local_decls[closure].ty.kind { if let ty::Closure(did, _) = self.body.local_decls[closure].ty.kind {
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did.expect_local()); let did = did.expect_local();
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did);
if let Some((span, name)) = if let Some((span, name)) =
self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id) self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id)
@ -119,7 +120,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// Check if we are just moving a closure after it has been invoked. // Check if we are just moving a closure after it has been invoked.
if let Some(target) = target { if let Some(target) = target {
if let ty::Closure(did, _) = self.body.local_decls[target].ty.kind { if let ty::Closure(did, _) = self.body.local_decls[target].ty.kind {
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did.expect_local()); let did = did.expect_local();
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did);
if let Some((span, name)) = if let Some((span, name)) =
self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id) self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id)

View file

@ -92,14 +92,14 @@ pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers { mir_borrowck, ..*providers }; *providers = Providers { mir_borrowck, ..*providers };
} }
fn mir_borrowck(tcx: TyCtxt<'_>, def_id: DefId) -> &BorrowCheckResult<'_> { fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &BorrowCheckResult<'_> {
let (input_body, promoted) = tcx.mir_validated(def_id); let (input_body, promoted) = tcx.mir_validated(def_id);
debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id)); debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id.to_def_id()));
let opt_closure_req = tcx.infer_ctxt().enter(|infcx| { let opt_closure_req = tcx.infer_ctxt().enter(|infcx| {
let input_body: &Body<'_> = &input_body.borrow(); let input_body: &Body<'_> = &input_body.borrow();
let promoted: &IndexVec<_, _> = &promoted.borrow(); let promoted: &IndexVec<_, _> = &promoted.borrow();
do_mir_borrowck(&infcx, input_body, promoted, def_id.expect_local()) do_mir_borrowck(&infcx, input_body, promoted, def_id)
}); });
debug!("mir_borrowck done"); debug!("mir_borrowck done");
@ -1268,7 +1268,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
match **aggregate_kind { match **aggregate_kind {
AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => { AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => {
let BorrowCheckResult { used_mut_upvars, .. } = let BorrowCheckResult { used_mut_upvars, .. } =
self.infcx.tcx.mir_borrowck(def_id); self.infcx.tcx.mir_borrowck(def_id.expect_local());
debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars); debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars);
for field in used_mut_upvars { for field in used_mut_upvars {
self.propagate_closure_used_mut_upvar(&operands[field.index()]); self.propagate_closure_used_mut_upvar(&operands[field.index()]);

View file

@ -36,7 +36,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if !self.tcx().is_closure(self.mir_def_id) { if !self.tcx().is_closure(self.mir_def_id) {
user_provided_sig = None; user_provided_sig = None;
} else { } else {
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id); let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id.expect_local());
user_provided_sig = match typeck_tables.user_provided_sigs.get(&self.mir_def_id) { user_provided_sig = match typeck_tables.user_provided_sigs.get(&self.mir_def_id) {
None => None, None => None,
Some(user_provided_poly_sig) => { Some(user_provided_poly_sig) => {

View file

@ -9,7 +9,7 @@ use rustc_data_structures::frozen::Frozen;
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::DefId; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
use rustc_infer::infer::canonical::QueryRegionConstraints; use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives::env::RegionBoundPairs; use rustc_infer::infer::outlives::env::RegionBoundPairs;
@ -1232,7 +1232,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let tcx = infcx.tcx; let tcx = infcx.tcx;
let param_env = self.param_env; let param_env = self.param_env;
let body = self.body; let body = self.body;
let concrete_opaque_types = &tcx.typeck_tables_of(anon_owner_def_id).concrete_opaque_types; let concrete_opaque_types =
&tcx.typeck_tables_of(anon_owner_def_id.expect_local()).concrete_opaque_types;
let mut opaque_type_values = Vec::new(); let mut opaque_type_values = Vec::new();
debug!("eq_opaque_type_and_type: mir_def_id={:?}", self.mir_def_id); debug!("eq_opaque_type_and_type: mir_def_id={:?}", self.mir_def_id);
@ -2568,7 +2569,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// clauses on the struct. // clauses on the struct.
AggregateKind::Closure(def_id, substs) AggregateKind::Closure(def_id, substs)
| AggregateKind::Generator(def_id, substs, _) => { | AggregateKind::Generator(def_id, substs, _) => {
self.prove_closure_bounds(tcx, *def_id, substs, location) self.prove_closure_bounds(tcx, def_id.expect_local(), substs, location)
} }
AggregateKind::Array(_) | AggregateKind::Tuple => ty::InstantiatedPredicates::empty(), AggregateKind::Array(_) | AggregateKind::Tuple => ty::InstantiatedPredicates::empty(),
@ -2583,14 +2584,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
fn prove_closure_bounds( fn prove_closure_bounds(
&mut self, &mut self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
def_id: DefId, def_id: LocalDefId,
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
location: Location, location: Location,
) -> ty::InstantiatedPredicates<'tcx> { ) -> ty::InstantiatedPredicates<'tcx> {
if let Some(ref closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements if let Some(ref closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements
{ {
let closure_constraints = QueryRegionConstraints { let closure_constraints = QueryRegionConstraints {
outlives: closure_region_requirements.apply_requirements(tcx, def_id, substs), outlives: closure_region_requirements.apply_requirements(
tcx,
def_id.to_def_id(),
substs,
),
// Presently, closures never propagate member // Presently, closures never propagate member
// constraints to their parents -- they are enforced // constraints to their parents -- they are enforced

View file

@ -498,7 +498,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let defining_ty = if self.mir_def_id == closure_base_def_id { let defining_ty = if self.mir_def_id == closure_base_def_id {
tcx.type_of(closure_base_def_id) tcx.type_of(closure_base_def_id)
} else { } else {
let tables = tcx.typeck_tables_of(self.mir_def_id); let tables = tcx.typeck_tables_of(self.mir_def_id.expect_local());
tables.node_type(self.mir_hir_id) tables.node_type(self.mir_hir_id)
}; };

View file

@ -289,9 +289,11 @@ pub fn const_eval_raw_provider<'tcx>(
let cid = key.value; let cid = key.value;
let def_id = cid.instance.def.def_id(); let def_id = cid.instance.def.def_id();
if def_id.is_local() && tcx.has_typeck_tables(def_id) { if let Some(def_id) = def_id.as_local() {
if let Some(error_reported) = tcx.typeck_tables_of(def_id).tainted_by_errors { if tcx.has_typeck_tables(def_id) {
return Err(ErrorHandled::Reported(error_reported)); if let Some(error_reported) = tcx.typeck_tables_of(def_id).tainted_by_errors {
return Err(ErrorHandled::Reported(error_reported));
}
} }
} }

View file

@ -402,9 +402,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> { ) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
// do not continue if typeck errors occurred (can only occur in local crate) // do not continue if typeck errors occurred (can only occur in local crate)
let did = instance.def_id(); let did = instance.def_id();
if did.is_local() && self.tcx.has_typeck_tables(did) { if let Some(did) = did.as_local() {
if let Some(error_reported) = self.tcx.typeck_tables_of(did).tainted_by_errors { if self.tcx.has_typeck_tables(did) {
throw_inval!(TypeckError(error_reported)) if let Some(error_reported) = self.tcx.typeck_tables_of(did).tainted_by_errors {
throw_inval!(TypeckError(error_reported))
}
} }
} }
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted); trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);

View file

@ -199,9 +199,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
// generators and closures. // generators and closures.
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => { ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
let mut name = None; let mut name = None;
if def_id.is_local() { if let Some(def_id) = def_id.as_local() {
let tables = self.ecx.tcx.typeck_tables_of(def_id); let tables = self.ecx.tcx.typeck_tables_of(def_id);
if let Some(upvars) = tables.upvar_list.get(&def_id) { if let Some(upvars) = tables.upvar_list.get(&def_id.to_def_id()) {
// Sometimes the index is beyond the number of upvars (seen // Sometimes the index is beyond the number of upvars (seen
// for a generator). // for a generator).
if let Some((&var_hir_id, _)) = upvars.get_index(field) { if let Some((&var_hir_id, _)) = upvars.get_index(field) {

View file

@ -919,7 +919,7 @@ struct RootCollector<'a, 'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
mode: MonoItemCollectionMode, mode: MonoItemCollectionMode,
output: &'a mut Vec<MonoItem<'tcx>>, output: &'a mut Vec<MonoItem<'tcx>>,
entry_fn: Option<(DefId, EntryFnType)>, entry_fn: Option<(LocalDefId, EntryFnType)>,
} }
impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> { impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
@ -1008,7 +1008,7 @@ impl RootCollector<'_, 'v> {
&& match self.mode { && match self.mode {
MonoItemCollectionMode::Eager => true, MonoItemCollectionMode::Eager => true,
MonoItemCollectionMode::Lazy => { MonoItemCollectionMode::Lazy => {
self.entry_fn.map(|(id, _)| id) == Some(def_id.to_def_id()) self.entry_fn.map(|(id, _)| id) == Some(def_id)
|| self.tcx.is_reachable_non_generic(def_id) || self.tcx.is_reachable_non_generic(def_id)
|| self || self
.tcx .tcx

View file

@ -132,7 +132,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
} }
&AggregateKind::Closure(def_id, _) | &AggregateKind::Generator(def_id, _, _) => { &AggregateKind::Closure(def_id, _) | &AggregateKind::Generator(def_id, _, _) => {
let UnsafetyCheckResult { violations, unsafe_blocks } = let UnsafetyCheckResult { violations, unsafe_blocks } =
self.tcx.unsafety_check_result(def_id); self.tcx.unsafety_check_result(def_id.expect_local());
self.register_violations(&violations, &unsafe_blocks); self.register_violations(&violations, &unsafe_blocks);
} }
}, },
@ -485,7 +485,7 @@ fn check_unused_unsafe(
intravisit::Visitor::visit_body(&mut visitor, body); intravisit::Visitor::visit_body(&mut visitor, body);
} }
fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult { fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckResult {
debug!("unsafety_violations({:?})", def_id); debug!("unsafety_violations({:?})", def_id);
// N.B., this borrow is valid because all the consumers of // N.B., this borrow is valid because all the consumers of
@ -494,21 +494,18 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
let param_env = tcx.param_env(def_id); let param_env = tcx.param_env(def_id);
let id = tcx.hir().as_local_hir_id(def_id.expect_local()); let id = tcx.hir().as_local_hir_id(def_id);
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) { let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
hir::BodyOwnerKind::Closure => (false, false), hir::BodyOwnerKind::Closure => (false, false),
hir::BodyOwnerKind::Fn => (is_const_fn(tcx, def_id), is_min_const_fn(tcx, def_id)), hir::BodyOwnerKind::Fn => {
(is_const_fn(tcx, def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
}
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false), hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false),
}; };
let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env); let mut checker = UnsafetyChecker::new(const_context, min_const_fn, body, tcx, param_env);
checker.visit_body(&body); checker.visit_body(&body);
check_unused_unsafe( check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks);
tcx,
def_id.expect_local(),
&checker.used_unsafe,
&mut checker.inherited_blocks,
);
UnsafetyCheckResult { UnsafetyCheckResult {
violations: checker.violations.into(), violations: checker.violations.into(),
unsafe_blocks: checker.inherited_blocks.into(), unsafe_blocks: checker.inherited_blocks.into(),
@ -600,7 +597,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
return; return;
} }
let UnsafetyCheckResult { violations, unsafe_blocks } = tcx.unsafety_check_result(def_id); let UnsafetyCheckResult { violations, unsafe_blocks } =
tcx.unsafety_check_result(def_id.expect_local());
for &UnsafetyViolation { source_info, description, details, kind } in violations.iter() { for &UnsafetyViolation { source_info, description, details, kind } in violations.iter() {
// Report an error. // Report an error.

View file

@ -1,8 +1,9 @@
use crate::{shim, util}; use crate::{shim, util};
use required_consts::RequiredConstsVisitor; use required_consts::RequiredConstsVisitor;
use rustc_ast::ast; use rustc_ast::ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
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 _;
@ -54,24 +55,24 @@ 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) tcx.mir_keys(def_id.krate).contains(&def_id.expect_local())
} }
/// 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) -> &DefIdSet { fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &FxHashSet<LocalDefId> {
assert_eq!(krate, LOCAL_CRATE); assert_eq!(krate, LOCAL_CRATE);
let mut set = DefIdSet::default(); let mut set = FxHashSet::default();
// All body-owners have MIR associated with them. // All body-owners have MIR associated with them.
set.extend(tcx.body_owners().map(LocalDefId::to_def_id)); set.extend(tcx.body_owners());
// Additionally, tuple struct/variant constructors have MIR, but // Additionally, tuple struct/variant constructors have MIR, but
// they don't have a BodyId, so we need to build them separately. // they don't have a BodyId, so we need to build them separately.
struct GatherCtors<'a, 'tcx> { struct GatherCtors<'a, 'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
set: &'a mut DefIdSet, set: &'a mut FxHashSet<LocalDefId>,
} }
impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> {
fn visit_variant_data( fn visit_variant_data(
@ -83,7 +84,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
_: Span, _: Span,
) { ) {
if let hir::VariantData::Tuple(_, hir_id) = *v { if let hir::VariantData::Tuple(_, hir_id) = *v {
self.set.insert(self.tcx.hir().local_def_id(hir_id).to_def_id()); self.set.insert(self.tcx.hir().local_def_id(hir_id));
} }
intravisit::walk_struct_def(self, v) intravisit::walk_struct_def(self, v)
} }
@ -211,17 +212,21 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
} }
fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<Body<'_>> { fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<Body<'_>> {
let def_id = def_id.expect_local();
// Unsafety check uses the raw mir, so make sure it is run // Unsafety check uses the raw mir, so make sure it is run
let _ = tcx.unsafety_check_result(def_id); let _ = tcx.unsafety_check_result(def_id);
let mut body = tcx.mir_built(def_id).steal(); let mut body = tcx.mir_built(def_id).steal();
util::dump_mir(tcx, None, "mir_map", &0, MirSource::item(def_id), &body, |_, _| Ok(())); util::dump_mir(tcx, None, "mir_map", &0, MirSource::item(def_id.to_def_id()), &body, |_, _| {
Ok(())
});
run_passes( run_passes(
tcx, tcx,
&mut body, &mut body,
InstanceDef::Item(def_id), InstanceDef::Item(def_id.to_def_id()),
None, None,
MirPhase::Const, MirPhase::Const,
&[&[ &[&[
@ -235,13 +240,13 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<Body<'_>> {
fn mir_validated( fn mir_validated(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
def_id: DefId, def_id: LocalDefId,
) -> (&'tcx Steal<Body<'tcx>>, &'tcx Steal<IndexVec<Promoted, Body<'tcx>>>) { ) -> (&'tcx Steal<Body<'tcx>>, &'tcx Steal<IndexVec<Promoted, Body<'tcx>>>) {
// Ensure that we compute the `mir_const_qualif` for constants at // Ensure that we compute the `mir_const_qualif` for constants at
// this point, before we steal the mir-const result. // this point, before we steal the mir-const result.
let _ = tcx.mir_const_qualif(def_id); let _ = tcx.mir_const_qualif(def_id.to_def_id());
let mut body = tcx.mir_const(def_id).steal(); let mut body = tcx.mir_const(def_id.to_def_id()).steal();
let mut required_consts = Vec::new(); let mut required_consts = Vec::new();
let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts); let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts);
@ -254,7 +259,7 @@ fn mir_validated(
run_passes( run_passes(
tcx, tcx,
&mut body, &mut body,
InstanceDef::Item(def_id), InstanceDef::Item(def_id.to_def_id()),
None, None,
MirPhase::Validated, MirPhase::Validated,
&[&[ &[&[
@ -271,7 +276,7 @@ fn mir_validated(
fn run_optimization_passes<'tcx>( fn run_optimization_passes<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &mut Body<'tcx>, body: &mut Body<'tcx>,
def_id: DefId, def_id: LocalDefId,
promoted: Option<Promoted>, promoted: Option<Promoted>,
) { ) {
let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[ let post_borrowck_cleanup: &[&dyn MirPass<'tcx>] = &[
@ -344,7 +349,7 @@ fn run_optimization_passes<'tcx>(
run_passes( run_passes(
tcx, tcx,
body, body,
InstanceDef::Item(def_id), InstanceDef::Item(def_id.to_def_id()),
promoted, promoted,
MirPhase::Optimized, MirPhase::Optimized,
&[ &[
@ -364,6 +369,8 @@ fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &Body<'_> {
return shim::build_adt_ctor(tcx, def_id); return shim::build_adt_ctor(tcx, def_id);
} }
let def_id = def_id.expect_local();
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to // (Mir-)Borrowck uses `mir_validated`, so we have to force it to
// execute before we can steal. // execute before we can steal.
tcx.ensure().mir_borrowck(def_id); tcx.ensure().mir_borrowck(def_id);
@ -382,6 +389,8 @@ fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &IndexVec<Promoted, Body<'_>>
return tcx.intern_promoted(IndexVec::new()); return tcx.intern_promoted(IndexVec::new());
} }
let def_id = def_id.expect_local();
tcx.ensure().mir_borrowck(def_id); tcx.ensure().mir_borrowck(def_id);
let (_, promoted) = tcx.mir_validated(def_id); let (_, promoted) = tcx.mir_validated(def_id);
let mut promoted = promoted.steal(); let mut promoted = promoted.steal();

View file

@ -868,5 +868,9 @@ fn write_user_type_annotations(body: &Body<'_>, w: &mut dyn Write) -> io::Result
} }
pub fn dump_mir_def_ids(tcx: TyCtxt<'_>, single: Option<DefId>) -> Vec<DefId> { pub fn dump_mir_def_ids(tcx: TyCtxt<'_>, single: Option<DefId>) -> Vec<DefId> {
if let Some(i) = single { vec![i] } else { tcx.mir_keys(LOCAL_CRATE).iter().cloned().collect() } if let Some(i) = single {
vec![i]
} else {
tcx.mir_keys(LOCAL_CRATE).iter().map(|def_id| def_id.to_def_id()).collect()
}
} }

View file

@ -21,8 +21,8 @@ use rustc_target::spec::PanicStrategy;
use super::lints; use super::lints;
crate fn mir_built(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::steal::Steal<Body<'_>> { crate fn mir_built(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &ty::steal::Steal<Body<'_>> {
tcx.alloc_steal_mir(mir_build(tcx, def_id.expect_local())) tcx.alloc_steal_mir(mir_build(tcx, def_id))
} }
/// Construct the MIR for a given `DefId`. /// Construct the MIR for a given `DefId`.
@ -181,7 +181,7 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Body<'_> {
build::construct_const(cx, body_id, return_ty, return_ty_span) build::construct_const(cx, body_id, return_ty, return_ty_span)
}; };
lints::check(tcx, &body, def_id.to_def_id()); lints::check(tcx, &body, def_id);
// The borrow checker will replace all the regions here with its own // The borrow checker will replace all the regions here with its own
// inference variables. There's no point having non-erased regions here. // inference variables. There's no point having non-erased regions here.

View file

@ -1,7 +1,7 @@
use rustc_data_structures::graph::iterate::{ use rustc_data_structures::graph::iterate::{
ControlFlow, NodeStatus, TriColorDepthFirstSearch, TriColorVisitor, ControlFlow, NodeStatus, TriColorDepthFirstSearch, TriColorVisitor,
}; };
use rustc_hir::def_id::DefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_middle::hir::map::blocks::FnLikeNode; use rustc_middle::hir::map::blocks::FnLikeNode;
use rustc_middle::mir::{BasicBlock, Body, Operand, TerminatorKind}; use rustc_middle::mir::{BasicBlock, Body, Operand, TerminatorKind};
@ -10,8 +10,8 @@ use rustc_middle::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt};
use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION; use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
use rustc_span::Span; use rustc_span::Span;
crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) { crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: LocalDefId) {
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let hir_id = tcx.hir().as_local_hir_id(def_id);
if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(hir_id)) { if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(hir_id)) {
if let FnKind::Closure(_) = fn_like_node.kind() { if let FnKind::Closure(_) = fn_like_node.kind() {
@ -20,12 +20,12 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) {
} }
// If this is trait/impl method, extract the trait's substs. // If this is trait/impl method, extract the trait's substs.
let trait_substs = match tcx.opt_associated_item(def_id) { let trait_substs = match tcx.opt_associated_item(def_id.to_def_id()) {
Some(AssocItem { Some(AssocItem {
container: AssocItemContainer::TraitContainer(trait_def_id), .. container: AssocItemContainer::TraitContainer(trait_def_id), ..
}) => { }) => {
let trait_substs_count = tcx.generics_of(trait_def_id).count(); let trait_substs_count = tcx.generics_of(trait_def_id).count();
&InternalSubsts::identity_for_item(tcx, def_id)[..trait_substs_count] &InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
} }
_ => &[], _ => &[],
}; };
@ -37,7 +37,7 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) {
vis.reachable_recursive_calls.sort(); vis.reachable_recursive_calls.sort();
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let hir_id = tcx.hir().as_local_hir_id(def_id);
let sp = tcx.sess.source_map().guess_head_span(tcx.hir().span(hir_id)); let sp = tcx.sess.source_map().guess_head_span(tcx.hir().span(hir_id));
tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, |lint| { tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, |lint| {
let mut db = lint.build("function cannot return without recursing"); let mut db = lint.build("function cannot return without recursing");
@ -57,7 +57,7 @@ struct NonRecursive;
struct Search<'mir, 'tcx> { struct Search<'mir, 'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &'mir Body<'tcx>, body: &'mir Body<'tcx>,
def_id: DefId, def_id: LocalDefId,
trait_substs: &'tcx [GenericArg<'tcx>], trait_substs: &'tcx [GenericArg<'tcx>],
reachable_recursive_calls: Vec<Span>, reachable_recursive_calls: Vec<Span>,
@ -84,7 +84,8 @@ impl<'mir, 'tcx> Search<'mir, 'tcx> {
// calling into an entirely different method (for example, a call from the default // calling into an entirely different method (for example, a call from the default
// method in the trait to `<A as Trait<B>>::method`, where `A` and/or `B` are // method in the trait to `<A as Trait<B>>::method`, where `A` and/or `B` are
// specific types). // specific types).
return call_fn_id == def_id && &call_substs[..trait_substs.len()] == trait_substs; return call_fn_id == def_id.to_def_id()
&& &call_substs[..trait_substs.len()] == trait_substs;
} }
false false

View file

@ -452,8 +452,7 @@ fn create_and_seed_worklist<'tcx>(
) )
.chain( .chain(
// Seed entry point // Seed entry point
tcx.entry_fn(LOCAL_CRATE) tcx.entry_fn(LOCAL_CRATE).map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id)),
.map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id.expect_local())),
) )
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -1,7 +1,7 @@
use rustc_ast::attr; use rustc_ast::attr;
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::{CrateNum, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::{HirId, ImplItem, Item, ItemKind, TraitItem}; use rustc_hir::{HirId, ImplItem, Item, ItemKind, TraitItem};
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
@ -48,7 +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<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
assert_eq!(cnum, LOCAL_CRATE); assert_eq!(cnum, LOCAL_CRATE);
let any_exe = let any_exe =
@ -143,13 +143,16 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
} }
} }
fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(DefId, EntryFnType)> { fn configure_main(
tcx: TyCtxt<'_>,
visitor: &EntryContext<'_, '_>,
) -> Option<(LocalDefId, EntryFnType)> {
if let Some((hir_id, _)) = visitor.start_fn { if let Some((hir_id, _)) = visitor.start_fn {
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Start)) Some((tcx.hir().local_def_id(hir_id), EntryFnType::Start))
} else if let Some((hir_id, _)) = visitor.attr_main_fn { } else if let Some((hir_id, _)) = visitor.attr_main_fn {
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Main)) Some((tcx.hir().local_def_id(hir_id), EntryFnType::Main))
} else if let Some((hir_id, _)) = visitor.main_fn { } else if let Some((hir_id, _)) = visitor.main_fn {
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Main)) Some((tcx.hir().local_def_id(hir_id), EntryFnType::Main))
} else { } else {
no_main_err(tcx, visitor); no_main_err(tcx, visitor);
None None
@ -211,7 +214,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
err.emit(); err.emit();
} }
pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(DefId, EntryFnType)> { pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(LocalDefId, EntryFnType)> {
tcx.entry_fn(LOCAL_CRATE) tcx.entry_fn(LOCAL_CRATE)
} }

View file

@ -132,7 +132,7 @@ impl Visitor<'tcx> for ItemVisitor<'tcx> {
let owner_def_id = self.tcx.hir().body_owner_def_id(body_id); let owner_def_id = self.tcx.hir().body_owner_def_id(body_id);
let body = self.tcx.hir().body(body_id); let body = self.tcx.hir().body(body_id);
let param_env = self.tcx.param_env(owner_def_id.to_def_id()); let param_env = self.tcx.param_env(owner_def_id.to_def_id());
let tables = self.tcx.typeck_tables_of(owner_def_id.to_def_id()); let tables = self.tcx.typeck_tables_of(owner_def_id);
ExprVisitor { tcx: self.tcx, param_env, tables }.visit_body(body); ExprVisitor { tcx: self.tcx, param_env, tables }.visit_body(body);
self.visit_body(body); self.visit_body(body);
} }

View file

@ -101,7 +101,7 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::*; use rustc_hir::def::*;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor};
use rustc_hir::{Expr, HirId, HirIdMap, HirIdSet, Node}; use rustc_hir::{Expr, HirId, HirIdMap, HirIdSet, Node};
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
@ -398,7 +398,7 @@ fn visit_fn<'tcx>(
intravisit::walk_fn(&mut fn_maps, fk, decl, body_id, sp, id); intravisit::walk_fn(&mut fn_maps, fk, decl, body_id, sp, id);
// compute liveness // compute liveness
let mut lsets = Liveness::new(&mut fn_maps, def_id.to_def_id()); let mut lsets = Liveness::new(&mut fn_maps, def_id);
let entry_ln = lsets.compute(&body.value); let entry_ln = lsets.compute(&body.value);
// check for various error conditions // check for various error conditions
@ -671,7 +671,7 @@ struct Liveness<'a, 'tcx> {
} }
impl<'a, 'tcx> Liveness<'a, 'tcx> { impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn new(ir: &'a mut IrMaps<'tcx>, def_id: DefId) -> Liveness<'a, 'tcx> { fn new(ir: &'a mut IrMaps<'tcx>, def_id: LocalDefId) -> Liveness<'a, 'tcx> {
// Special nodes and variables: // Special nodes and variables:
// - exit_ln represents the end of the fn, either by return or panic // - exit_ln represents the end of the fn, either by return or panic
// - implicit_ret_var is a pseudo-variable that represents // - implicit_ret_var is a pseudo-variable that represents

View file

@ -10,7 +10,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, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, 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;
@ -1174,7 +1174,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
struct TypePrivacyVisitor<'a, 'tcx> { struct TypePrivacyVisitor<'a, 'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
tables: &'a ty::TypeckTables<'tcx>, tables: &'a ty::TypeckTables<'tcx>,
current_item: DefId, current_item: LocalDefId,
in_body: bool, in_body: bool,
span: Span, span: Span,
empty_tables: &'a ty::TypeckTables<'tcx>, empty_tables: &'a ty::TypeckTables<'tcx>,
@ -1182,7 +1182,9 @@ struct TypePrivacyVisitor<'a, 'tcx> {
impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> { impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> {
fn item_is_accessible(&self, did: DefId) -> bool { fn item_is_accessible(&self, did: DefId) -> bool {
def_id_visibility(self.tcx, did).0.is_accessible_from(self.current_item, self.tcx) def_id_visibility(self.tcx, did)
.0
.is_accessible_from(self.current_item.to_def_id(), self.tcx)
} }
// Take node-id of an expression or pattern and check its type for privacy. // Take node-id of an expression or pattern and check its type for privacy.
@ -1387,10 +1389,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
// Check types in item interfaces. // Check types in item interfaces.
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let orig_current_item = mem::replace( let orig_current_item =
&mut self.current_item, mem::replace(&mut self.current_item, self.tcx.hir().local_def_id(item.hir_id));
self.tcx.hir().local_def_id(item.hir_id).to_def_id(),
);
let orig_in_body = mem::replace(&mut self.in_body, false); let orig_in_body = mem::replace(&mut self.in_body, false);
let orig_tables = let orig_tables =
mem::replace(&mut self.tables, item_tables(self.tcx, item.hir_id, self.empty_tables)); mem::replace(&mut self.tables, item_tables(self.tcx, item.hir_id, self.empty_tables));
@ -2076,7 +2076,7 @@ pub fn provide(providers: &mut Providers<'_>) {
}; };
} }
fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: DefId) { fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
let empty_tables = ty::TypeckTables::empty(None); let empty_tables = ty::TypeckTables::empty(None);
// Check privacy of names not checked in previous compilation stages. // Check privacy of names not checked in previous compilation stages.
@ -2086,7 +2086,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: DefId) {
current_item: None, current_item: None,
empty_tables: &empty_tables, empty_tables: &empty_tables,
}; };
let (module, span, hir_id) = tcx.hir().get_module(module_def_id.expect_local()); let (module, span, hir_id) = tcx.hir().get_module(module_def_id);
intravisit::walk_mod(&mut visitor, module, hir_id); intravisit::walk_mod(&mut visitor, module, hir_id);

View file

@ -107,7 +107,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
where where
F: FnOnce(&mut Self), F: FnOnce(&mut Self),
{ {
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id).to_def_id(); let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id);
let tables = if self.tcx.has_typeck_tables(item_def_id) { let tables = if self.tcx.has_typeck_tables(item_def_id) {
self.tcx.typeck_tables_of(item_def_id) self.tcx.typeck_tables_of(item_def_id)
@ -1183,7 +1183,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
// Make a comma-separated list of names of imported modules. // Make a comma-separated list of names of imported modules.
let def_id = self.tcx.hir().local_def_id_from_node_id(id); let def_id = self.tcx.hir().local_def_id_from_node_id(id);
let names = self.tcx.names_imported_by_glob_use(def_id.to_def_id()); let names = self.tcx.names_imported_by_glob_use(def_id);
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect(); let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
// Otherwise it's a span with wrong macro expansion info, which // Otherwise it's a span with wrong macro expansion info, which

View file

@ -1243,7 +1243,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let tables: &TypeckTables<'tcx> = match &in_progress_tables { let tables: &TypeckTables<'tcx> = match &in_progress_tables {
Some(t) if t.hir_owner.map(|owner| owner.to_def_id()) == Some(generator_did_root) => t, Some(t) if t.hir_owner.map(|owner| owner.to_def_id()) == Some(generator_did_root) => t,
_ => { _ => {
query_tables = self.tcx.typeck_tables_of(generator_did); query_tables = self.tcx.typeck_tables_of(generator_did.expect_local());
&query_tables &query_tables
} }
}; };

View file

@ -754,16 +754,16 @@ fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) {
}); });
} }
fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) { fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
wfcheck::check_item_well_formed(tcx, def_id.expect_local()); wfcheck::check_item_well_formed(tcx, def_id);
} }
fn check_trait_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) { fn check_trait_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
wfcheck::check_trait_item(tcx, def_id.expect_local()); wfcheck::check_trait_item(tcx, def_id);
} }
fn check_impl_item_well_formed(tcx: TyCtxt<'_>, def_id: DefId) { fn check_impl_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
wfcheck::check_impl_item(tcx, def_id.expect_local()); wfcheck::check_impl_item(tcx, def_id);
} }
pub fn provide(providers: &mut Providers<'_>) { pub fn provide(providers: &mut Providers<'_>) {
@ -853,7 +853,7 @@ fn has_typeck_tables(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
} }
} }
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: DefId) -> &DefIdSet { fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &DefIdSet {
&*tcx.typeck_tables_of(def_id).used_trait_imports &*tcx.typeck_tables_of(def_id).used_trait_imports
} }
@ -968,8 +968,8 @@ where
val.fold_with(&mut FixupFolder { tcx }) val.fold_with(&mut FixupFolder { tcx })
} }
fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &ty::TypeckTables<'tcx> { fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckTables<'tcx> {
let fallback = move || tcx.type_of(def_id); let fallback = move || tcx.type_of(def_id.to_def_id());
typeck_tables_of_with_fallback(tcx, def_id, fallback) typeck_tables_of_with_fallback(tcx, def_id, fallback)
} }
@ -977,11 +977,10 @@ fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &ty::TypeckTables
/// Currently only used for type inference of `static`s and `const`s to avoid type cycle errors. /// Currently only used for type inference of `static`s and `const`s to avoid type cycle errors.
fn diagnostic_only_typeck_tables_of<'tcx>( fn diagnostic_only_typeck_tables_of<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
def_id: DefId, def_id: LocalDefId,
) -> &ty::TypeckTables<'tcx> { ) -> &ty::TypeckTables<'tcx> {
assert!(def_id.is_local());
let fallback = move || { let fallback = move || {
let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id.expect_local())); let span = tcx.hir().span(tcx.hir().as_local_hir_id(def_id));
tcx.sess.delay_span_bug(span, "diagnostic only typeck table used"); tcx.sess.delay_span_bug(span, "diagnostic only typeck table used");
tcx.types.err tcx.types.err
}; };
@ -990,17 +989,17 @@ fn diagnostic_only_typeck_tables_of<'tcx>(
fn typeck_tables_of_with_fallback<'tcx>( fn typeck_tables_of_with_fallback<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
def_id: DefId, def_id: LocalDefId,
fallback: impl Fn() -> Ty<'tcx> + 'tcx, fallback: impl Fn() -> Ty<'tcx> + 'tcx,
) -> &'tcx ty::TypeckTables<'tcx> { ) -> &'tcx ty::TypeckTables<'tcx> {
// Closures' tables come from their outermost function, // Closures' tables come from their outermost function,
// as they are part of the same "inference environment". // as they are part of the same "inference environment".
let outer_def_id = tcx.closure_base_def_id(def_id); let outer_def_id = tcx.closure_base_def_id(def_id.to_def_id()).expect_local();
if outer_def_id != def_id { if outer_def_id != def_id {
return tcx.typeck_tables_of(outer_def_id); return tcx.typeck_tables_of(outer_def_id);
} }
let id = tcx.hir().as_local_hir_id(def_id.expect_local()); let id = tcx.hir().as_local_hir_id(def_id);
let span = tcx.hir().span(id); let span = tcx.hir().span(id);
// Figure out what primary body this item has. // Figure out what primary body this item has.
@ -1009,7 +1008,7 @@ fn typeck_tables_of_with_fallback<'tcx>(
}); });
let body = tcx.hir().body(body_id); let body = tcx.hir().body(body_id);
let tables = Inherited::build(tcx, def_id.expect_local()).enter(|inh| { let tables = Inherited::build(tcx, def_id).enter(|inh| {
let param_env = tcx.param_env(def_id); let param_env = tcx.param_env(def_id);
let fcx = if let (Some(header), Some(decl)) = (fn_header, fn_decl) { let fcx = if let (Some(header), Some(decl)) = (fn_header, fn_decl) {
let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() { let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() {
@ -1029,7 +1028,7 @@ fn typeck_tables_of_with_fallback<'tcx>(
check_abi(tcx, span, fn_sig.abi()); check_abi(tcx, span, fn_sig.abi());
// Compute the fty from point of view of inside the fn. // Compute the fty from point of view of inside the fn.
let fn_sig = tcx.liberate_late_bound_regions(def_id, &fn_sig); let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), &fn_sig);
let fn_sig = inh.normalize_associated_types_in( let fn_sig = inh.normalize_associated_types_in(
body.value.span, body.value.span,
body_id.hir_id, body_id.hir_id,
@ -1121,7 +1120,7 @@ fn typeck_tables_of_with_fallback<'tcx>(
// because they don't constrain other type variables. // because they don't constrain other type variables.
fcx.closure_analyze(body); fcx.closure_analyze(body);
assert!(fcx.deferred_call_resolutions.borrow().is_empty()); assert!(fcx.deferred_call_resolutions.borrow().is_empty());
fcx.resolve_generator_interiors(def_id); fcx.resolve_generator_interiors(def_id.to_def_id());
for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) { for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) {
let ty = fcx.normalize_ty(span, ty); let ty = fcx.normalize_ty(span, ty);
@ -1452,7 +1451,7 @@ fn check_fn<'a, 'tcx>(
// Check that the main return type implements the termination trait. // Check that the main return type implements the termination trait.
if let Some(term_id) = tcx.lang_items().termination() { if let Some(term_id) = tcx.lang_items().termination() {
if let Some((def_id, EntryFnType::Main)) = tcx.entry_fn(LOCAL_CRATE) { if let Some((def_id, EntryFnType::Main)) = tcx.entry_fn(LOCAL_CRATE) {
let main_id = hir.as_local_hir_id(def_id.expect_local()); let main_id = hir.as_local_hir_id(def_id);
if main_id == fn_id { if main_id == fn_id {
let substs = tcx.mk_substs_trait(declared_ret_ty, &[]); let substs = tcx.mk_substs_trait(declared_ret_ty, &[]);
let trait_ref = ty::TraitRef::new(term_id, substs); let trait_ref = ty::TraitRef::new(term_id, substs);

View file

@ -77,7 +77,7 @@ use crate::check::FnCtxt;
use crate::mem_categorization as mc; use crate::mem_categorization as mc;
use crate::middle::region; use crate::middle::region;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::PatKind; use rustc_hir::PatKind;
use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::infer::outlives::env::OutlivesEnvironment;
@ -109,7 +109,7 @@ macro_rules! ignore_err {
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn regionck_expr(&self, body: &'tcx hir::Body<'tcx>) { pub fn regionck_expr(&self, body: &'tcx hir::Body<'tcx>) {
let subject = self.tcx.hir().body_owner_def_id(body.id()).to_def_id(); let subject = self.tcx.hir().body_owner_def_id(body.id());
let id = body.value.hir_id; let id = body.value.hir_id;
let mut rcx = let mut rcx =
RegionCtxt::new(self, RepeatingScope(id), id, Subject(subject), self.param_env); RegionCtxt::new(self, RepeatingScope(id), id, Subject(subject), self.param_env);
@ -135,7 +135,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self, self,
RepeatingScope(item_id), RepeatingScope(item_id),
item_id, item_id,
Subject(subject.to_def_id()), Subject(subject),
self.param_env, self.param_env,
); );
rcx.outlives_environment.add_implied_bounds(self, wf_tys, item_id, span); rcx.outlives_environment.add_implied_bounds(self, wf_tys, item_id, span);
@ -154,7 +154,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// constraints to add. /// constraints to add.
pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body<'tcx>) { pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body<'tcx>) {
debug!("regionck_fn(id={})", fn_id); debug!("regionck_fn(id={})", fn_id);
let subject = self.tcx.hir().body_owner_def_id(body.id()).to_def_id(); let subject = self.tcx.hir().body_owner_def_id(body.id());
let hir_id = body.value.hir_id; let hir_id = body.value.hir_id;
let mut rcx = let mut rcx =
RegionCtxt::new(self, RepeatingScope(hir_id), hir_id, Subject(subject), self.param_env); RegionCtxt::new(self, RepeatingScope(hir_id), hir_id, Subject(subject), self.param_env);
@ -180,7 +180,7 @@ pub struct RegionCtxt<'a, 'tcx> {
// id of innermost fn body id // id of innermost fn body id
body_id: hir::HirId, body_id: hir::HirId,
body_owner: DefId, body_owner: LocalDefId,
// call_site scope of innermost fn // call_site scope of innermost fn
call_site_scope: Option<region::Scope>, call_site_scope: Option<region::Scope>,
@ -189,7 +189,7 @@ pub struct RegionCtxt<'a, 'tcx> {
repeating_scope: hir::HirId, repeating_scope: hir::HirId,
// id of AST node being analyzed (the subject of the analysis). // id of AST node being analyzed (the subject of the analysis).
subject_def_id: DefId, subject_def_id: LocalDefId,
} }
impl<'a, 'tcx> Deref for RegionCtxt<'a, 'tcx> { impl<'a, 'tcx> Deref for RegionCtxt<'a, 'tcx> {
@ -200,7 +200,7 @@ impl<'a, 'tcx> Deref for RegionCtxt<'a, 'tcx> {
} }
pub struct RepeatingScope(hir::HirId); pub struct RepeatingScope(hir::HirId);
pub struct Subject(DefId); pub struct Subject(LocalDefId);
impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
pub fn new( pub fn new(
@ -290,7 +290,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
let body_id = body.id(); let body_id = body.id();
self.body_id = body_id.hir_id; self.body_id = body_id.hir_id;
self.body_owner = self.tcx.hir().body_owner_def_id(body_id).to_def_id(); self.body_owner = self.tcx.hir().body_owner_def_id(body_id);
let call_site = let call_site =
region::Scope { id: body.value.hir_id.local_id, data: region::ScopeData::CallSite }; region::Scope { id: body.value.hir_id.local_id, data: region::ScopeData::CallSite };
@ -353,7 +353,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
); );
self.fcx.resolve_regions_and_report_errors( self.fcx.resolve_regions_and_report_errors(
self.subject_def_id, self.subject_def_id.to_def_id(),
&self.region_scope_tree, &self.region_scope_tree,
&self.outlives_environment, &self.outlives_environment,
mode, mode,

View file

@ -146,8 +146,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
let body_owner_def_id = self.tcx.hir().body_owner_def_id(body.id()).to_def_id(); let body_owner_def_id = self.tcx.hir().body_owner_def_id(body.id());
assert_eq!(body_owner_def_id, closure_def_id); assert_eq!(body_owner_def_id.to_def_id(), closure_def_id);
let mut delegate = InferBorrowKind { let mut delegate = InferBorrowKind {
fcx: self, fcx: self,
closure_def_id, closure_def_id,

View file

@ -12,7 +12,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
let mut used_trait_imports = DefIdSet::default(); let mut used_trait_imports = DefIdSet::default();
for &body_id in tcx.hir().krate().bodies.keys() { for &body_id in tcx.hir().krate().bodies.keys() {
let item_def_id = tcx.hir().body_owner_def_id(body_id); let item_def_id = tcx.hir().body_owner_def_id(body_id);
let imports = tcx.used_trait_imports(item_def_id.to_def_id()); let imports = tcx.used_trait_imports(item_def_id);
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports); debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
used_trait_imports.extend(imports.iter()); used_trait_imports.extend(imports.iter());
} }

View file

@ -295,7 +295,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
} }
fn get_type_parameter_bounds(&self, span: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> { fn get_type_parameter_bounds(&self, span: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> {
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id)) self.tcx.at(span).type_param_predicates((self.item_def_id, def_id.expect_local()))
} }
fn re_infer(&self, _: Option<&ty::GenericParamDef>, _: Span) -> Option<ty::Region<'tcx>> { fn re_infer(&self, _: Option<&ty::GenericParamDef>, _: Span) -> Option<ty::Region<'tcx>> {
@ -478,7 +478,7 @@ fn get_new_lifetime_name<'tcx>(
/// `X: Foo` where `X` is the type parameter `def_id`. /// `X: Foo` where `X` is the type parameter `def_id`.
fn type_param_predicates( fn type_param_predicates(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
(item_def_id, def_id): (DefId, DefId), (item_def_id, def_id): (DefId, LocalDefId),
) -> ty::GenericPredicates<'_> { ) -> ty::GenericPredicates<'_> {
use rustc_hir::*; use rustc_hir::*;
@ -486,11 +486,11 @@ fn type_param_predicates(
// written inline like `<T: Foo>` or in a where-clause like // written inline like `<T: Foo>` or in a where-clause like
// `where T: Foo`. // `where T: Foo`.
let param_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let param_id = tcx.hir().as_local_hir_id(def_id);
let param_owner = tcx.hir().ty_param_owner(param_id); let param_owner = tcx.hir().ty_param_owner(param_id);
let param_owner_def_id = tcx.hir().local_def_id(param_owner); let param_owner_def_id = tcx.hir().local_def_id(param_owner);
let generics = tcx.generics_of(param_owner_def_id); let generics = tcx.generics_of(param_owner_def_id);
let index = generics.param_def_id_to_index[&def_id]; let index = generics.param_def_id_to_index[&def_id.to_def_id()];
let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(param_id)); let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(param_id));
// Don't look for bounds where the type parameter isn't in scope. // Don't look for bounds where the type parameter isn't in scope.
@ -503,7 +503,7 @@ fn type_param_predicates(
let mut result = parent let mut result = parent
.map(|parent| { .map(|parent| {
let icx = ItemCtxt::new(tcx, parent); let icx = ItemCtxt::new(tcx, parent);
icx.get_type_parameter_bounds(DUMMY_SP, def_id) icx.get_type_parameter_bounds(DUMMY_SP, def_id.to_def_id())
}) })
.unwrap_or_default(); .unwrap_or_default();
let mut extend = None; let mut extend = None;
@ -1459,9 +1459,10 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
use rustc_hir::Node::*; use rustc_hir::Node::*;
use rustc_hir::*; use rustc_hir::*;
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); let def_id = def_id.expect_local();
let hir_id = tcx.hir().as_local_hir_id(def_id);
let icx = ItemCtxt::new(tcx, def_id); let icx = ItemCtxt::new(tcx, def_id.to_def_id());
match tcx.hir().get(hir_id) { match tcx.hir().get(hir_id) {
TraitItem(hir::TraitItem { TraitItem(hir::TraitItem {
@ -1516,7 +1517,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
.. ..
}) => { }) => {
let abi = tcx.hir().get_foreign_abi(hir_id); let abi = tcx.hir().get_foreign_abi(hir_id);
compute_sig_of_foreign_fn_decl(tcx, def_id, fn_decl, abi, ident) compute_sig_of_foreign_fn_decl(tcx, def_id.to_def_id(), fn_decl, abi, ident)
} }
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor_hir_id().is_some() => { Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor_hir_id().is_some() => {

View file

@ -34,7 +34,13 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
TraitItemKind::Const(ref ty, body_id) => body_id TraitItemKind::Const(ref ty, body_id) => body_id
.and_then(|body_id| { .and_then(|body_id| {
if is_suggestable_infer_ty(ty) { if is_suggestable_infer_ty(ty) {
Some(infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)) Some(infer_placeholder_type(
tcx,
def_id.expect_local(),
body_id,
ty.span,
item.ident,
))
} else { } else {
None None
} }
@ -53,7 +59,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
} }
ImplItemKind::Const(ref ty, body_id) => { ImplItemKind::Const(ref ty, body_id) => {
if is_suggestable_infer_ty(ty) { if is_suggestable_infer_ty(ty) {
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident) infer_placeholder_type(tcx, def_id.expect_local(), body_id, ty.span, item.ident)
} else { } else {
icx.to_ty(ty) icx.to_ty(ty)
} }
@ -78,7 +84,13 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
match item.kind { match item.kind {
ItemKind::Static(ref ty, .., body_id) | ItemKind::Const(ref ty, body_id) => { ItemKind::Static(ref ty, .., body_id) | ItemKind::Const(ref ty, body_id) => {
if is_suggestable_infer_ty(ty) { if is_suggestable_infer_ty(ty) {
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident) infer_placeholder_type(
tcx,
def_id.expect_local(),
body_id,
ty.span,
item.ident,
)
} else { } else {
icx.to_ty(ty) icx.to_ty(ty)
} }
@ -102,13 +114,13 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: Some(owner), origin, .. }) => { ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: Some(owner), origin, .. }) => {
let concrete_types = match origin { let concrete_types = match origin {
OpaqueTyOrigin::FnReturn | OpaqueTyOrigin::AsyncFn => { OpaqueTyOrigin::FnReturn | OpaqueTyOrigin::AsyncFn => {
&tcx.mir_borrowck(owner).concrete_opaque_types &tcx.mir_borrowck(owner.expect_local()).concrete_opaque_types
} }
OpaqueTyOrigin::Misc => { OpaqueTyOrigin::Misc => {
// We shouldn't leak borrowck results through impl trait in bindings. // We shouldn't leak borrowck results through impl trait in bindings.
// For example, we shouldn't be able to tell if `x` in // For example, we shouldn't be able to tell if `x` in
// `let x: impl Sized + 'a = &()` has type `&'static ()` or `&'a ()`. // `let x: impl Sized + 'a = &()` has type `&'static ()` or `&'a ()`.
&tcx.typeck_tables_of(owner).concrete_opaque_types &tcx.typeck_tables_of(owner.expect_local()).concrete_opaque_types
} }
OpaqueTyOrigin::TypeAlias => { OpaqueTyOrigin::TypeAlias => {
span_bug!(item.span, "Type alias impl trait shouldn't have an owner") span_bug!(item.span, "Type alias impl trait shouldn't have an owner")
@ -126,7 +138,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
), ),
); );
if let Some(ErrorReported) = if let Some(ErrorReported) =
tcx.typeck_tables_of(owner).tainted_by_errors tcx.typeck_tables_of(owner.expect_local()).tainted_by_errors
{ {
// Some error in the // Some error in the
// owner fn prevented us from populating // owner fn prevented us from populating
@ -405,7 +417,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
} }
impl ConstraintLocator<'_> { impl ConstraintLocator<'_> {
fn check(&mut self, def_id: DefId) { fn check(&mut self, def_id: LocalDefId) {
// Don't try to check items that cannot possibly constrain the type. // Don't try to check items that cannot possibly constrain the type.
if !self.tcx.has_typeck_tables(def_id) { if !self.tcx.has_typeck_tables(def_id) {
debug!( debug!(
@ -512,24 +524,24 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
if let hir::ExprKind::Closure(..) = ex.kind { if let hir::ExprKind::Closure(..) = ex.kind {
let def_id = self.tcx.hir().local_def_id(ex.hir_id); let def_id = self.tcx.hir().local_def_id(ex.hir_id);
self.check(def_id.to_def_id()); self.check(def_id);
} }
intravisit::walk_expr(self, ex); intravisit::walk_expr(self, ex);
} }
fn visit_item(&mut self, it: &'tcx Item<'tcx>) { fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
debug!("find_existential_constraints: visiting {:?}", it); debug!("find_existential_constraints: visiting {:?}", it);
let def_id = self.tcx.hir().local_def_id(it.hir_id).to_def_id(); let def_id = self.tcx.hir().local_def_id(it.hir_id);
// The opaque type itself or its children are not within its reveal scope. // The opaque type itself or its children are not within its reveal scope.
if def_id != self.def_id { if def_id.to_def_id() != self.def_id {
self.check(def_id); self.check(def_id);
intravisit::walk_item(self, it); intravisit::walk_item(self, it);
} }
} }
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) { fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
debug!("find_existential_constraints: visiting {:?}", it); debug!("find_existential_constraints: visiting {:?}", it);
let def_id = self.tcx.hir().local_def_id(it.hir_id).to_def_id(); let def_id = self.tcx.hir().local_def_id(it.hir_id);
// The opaque type itself or its children are not within its reveal scope. // The opaque type itself or its children are not within its reveal scope.
if def_id != self.def_id { if def_id.to_def_id() != self.def_id {
self.check(def_id); self.check(def_id);
intravisit::walk_impl_item(self, it); intravisit::walk_impl_item(self, it);
} }
@ -537,7 +549,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) { fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
debug!("find_existential_constraints: visiting {:?}", it); debug!("find_existential_constraints: visiting {:?}", it);
let def_id = self.tcx.hir().local_def_id(it.hir_id); let def_id = self.tcx.hir().local_def_id(it.hir_id);
self.check(def_id.to_def_id()); self.check(def_id);
intravisit::walk_trait_item(self, it); intravisit::walk_trait_item(self, it);
} }
} }
@ -586,7 +598,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
fn infer_placeholder_type( fn infer_placeholder_type(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
def_id: DefId, def_id: LocalDefId,
body_id: hir::BodyId, body_id: hir::BodyId,
span: Span, span: Span,
item_ident: Ident, item_ident: Ident,

View file

@ -9,7 +9,7 @@ pub use mc::{Place, PlaceBase, Projection};
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::DefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::PatKind; use rustc_hir::PatKind;
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_middle::ty::{self, adjustment, TyCtxt}; use rustc_middle::ty::{self, adjustment, TyCtxt};
@ -84,7 +84,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
pub fn new( pub fn new(
delegate: &'a mut (dyn Delegate<'tcx> + 'a), delegate: &'a mut (dyn Delegate<'tcx> + 'a),
infcx: &'a InferCtxt<'a, 'tcx>, infcx: &'a InferCtxt<'a, 'tcx>,
body_owner: DefId, body_owner: LocalDefId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
tables: &'a ty::TypeckTables<'tcx>, tables: &'a ty::TypeckTables<'tcx>,
) -> Self { ) -> Self {

View file

@ -303,8 +303,8 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
fn check_for_entry_fn(tcx: TyCtxt<'_>) { fn check_for_entry_fn(tcx: TyCtxt<'_>) {
match tcx.entry_fn(LOCAL_CRATE) { match tcx.entry_fn(LOCAL_CRATE) {
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id.expect_local()), Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id.expect_local()), Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),
_ => {} _ => {}
} }
} }

View file

@ -55,7 +55,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
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; use rustc_hir::def_id::LocalDefId;
use rustc_hir::PatKind; use rustc_hir::PatKind;
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_span::Span; use rustc_span::Span;
@ -140,7 +140,7 @@ crate struct MemCategorizationContext<'a, 'tcx> {
crate tables: &'a ty::TypeckTables<'tcx>, crate tables: &'a ty::TypeckTables<'tcx>,
infcx: &'a InferCtxt<'a, 'tcx>, infcx: &'a InferCtxt<'a, 'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body_owner: DefId, body_owner: LocalDefId,
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>, upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
} }
@ -151,7 +151,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
crate fn new( crate fn new(
infcx: &'a InferCtxt<'a, 'tcx>, infcx: &'a InferCtxt<'a, 'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body_owner: DefId, body_owner: LocalDefId,
tables: &'a ty::TypeckTables<'tcx>, tables: &'a ty::TypeckTables<'tcx>,
) -> MemCategorizationContext<'a, 'tcx> { ) -> MemCategorizationContext<'a, 'tcx> {
MemCategorizationContext { MemCategorizationContext {
@ -473,7 +473,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
let upvar_id = ty::UpvarId { let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_id }, var_path: ty::UpvarPath { hir_id: var_id },
closure_expr_id: closure_expr_def_id.expect_local(), closure_expr_id: closure_expr_def_id,
}; };
let var_ty = self.node_ty(var_id)?; let var_ty = self.node_ty(var_id)?;