Skip to content

Commit c9f6ffc

Browse files
committed
Change return type of entry_fn query to return a LocalDefId
1 parent 3877f54 commit c9f6ffc

File tree

10 files changed

+24
-22
lines changed

10 files changed

+24
-22
lines changed

src/librustc_codegen_llvm/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
290290
spflags |= DISPFlags::SPFlagOptimized;
291291
}
292292
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
293-
if id == def_id {
293+
if id.to_def_id() == def_id {
294294
spflags |= DISPFlags::SPFlagMainSubprogram;
295295
}
296296
}

src/librustc_codegen_ssa/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_data_structures::fx::FxHashMap;
3030
use rustc_data_structures::profiling::print_time_passes_entry;
3131
use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator};
3232
use rustc_hir as hir;
33-
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
33+
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
3434
use rustc_hir::lang_items::StartFnLangItem;
3535
use rustc_index::vec::Idx;
3636
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
@@ -397,7 +397,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
397397
None => return None,
398398
};
399399

400-
let instance = Instance::mono(cx.tcx(), main_def_id);
400+
let instance = Instance::mono(cx.tcx(), main_def_id.to_def_id());
401401

402402
if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
403403
// 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>>(
416416
cx: &'a Bx::CodegenCx,
417417
sp: Span,
418418
rust_main: Bx::Value,
419-
rust_main_def_id: DefId,
419+
rust_main_def_id: LocalDefId,
420420
use_start_lang_item: bool,
421421
) -> Bx::Function {
422422
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`,

src/librustc_interface/queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'tcx> Queries<'tcx> {
293293
_ => return,
294294
};
295295

296-
let attrs = &*tcx.get_attrs(def_id);
296+
let attrs = &*tcx.get_attrs(def_id.to_def_id());
297297
let attrs = attrs.iter().filter(|attr| attr.check_name(sym::rustc_error));
298298
for attr in attrs {
299299
match attr.meta_item_list() {

src/librustc_middle/mir/mono.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::base_n;
77
use rustc_data_structures::fingerprint::Fingerprint;
88
use rustc_data_structures::fx::FxHashMap;
99
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
10-
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
10+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
1111
use rustc_hir::HirId;
1212
use rustc_session::config::OptLevel;
1313
use rustc_span::source_map::Span;
@@ -95,7 +95,7 @@ impl<'tcx> MonoItem<'tcx> {
9595
// linkage, then we'll be creating a globally shared version.
9696
if self.explicit_linkage(tcx).is_some()
9797
|| !instance.def.generates_cgu_internal_copy(tcx)
98-
|| Some(instance.def_id()) == entry_def_id
98+
|| Some(instance.def_id()) == entry_def_id.map(LocalDefId::to_def_id)
9999
{
100100
return InstantiationMode::GloballyShared { may_conflict: false };
101101
}

src/librustc_middle/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ rustc_queries! {
880880

881881
/// Identifies the entry-point (e.g., the `main` function) for a given
882882
/// crate, returning `None` if there is no entry point (such as for library crates).
883-
query entry_fn(_: CrateNum) -> Option<(DefId, EntryFnType)> {
883+
query entry_fn(_: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
884884
desc { "looking up the entry function of a crate" }
885885
}
886886
query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {

src/librustc_mir/monomorphize/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ struct RootCollector<'a, 'tcx> {
919919
tcx: TyCtxt<'tcx>,
920920
mode: MonoItemCollectionMode,
921921
output: &'a mut Vec<MonoItem<'tcx>>,
922-
entry_fn: Option<(DefId, EntryFnType)>,
922+
entry_fn: Option<(LocalDefId, EntryFnType)>,
923923
}
924924

925925
impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
@@ -1008,7 +1008,7 @@ impl RootCollector<'_, 'v> {
10081008
&& match self.mode {
10091009
MonoItemCollectionMode::Eager => true,
10101010
MonoItemCollectionMode::Lazy => {
1011-
self.entry_fn.map(|(id, _)| id) == Some(def_id.to_def_id())
1011+
self.entry_fn.map(|(id, _)| id) == Some(def_id)
10121012
|| self.tcx.is_reachable_non_generic(def_id)
10131013
|| self
10141014
.tcx

src/librustc_passes/dead.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,7 @@ fn create_and_seed_worklist<'tcx>(
452452
)
453453
.chain(
454454
// Seed entry point
455-
tcx.entry_fn(LOCAL_CRATE)
456-
.map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id.expect_local())),
455+
tcx.entry_fn(LOCAL_CRATE).map(|(def_id, _)| tcx.hir().as_local_hir_id(def_id)),
457456
)
458457
.collect::<Vec<_>>();
459458

src/librustc_passes/entry.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::attr;
22
use rustc_ast::entry::EntryPointType;
33
use rustc_errors::struct_span_err;
4-
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
4+
use rustc_hir::def_id::{CrateNum, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
55
use rustc_hir::itemlikevisit::ItemLikeVisitor;
66
use rustc_hir::{HirId, ImplItem, Item, ItemKind, TraitItem};
77
use rustc_middle::hir::map::Map;
@@ -48,7 +48,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
4848
}
4949
}
5050

51-
fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(DefId, EntryFnType)> {
51+
fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
5252
assert_eq!(cnum, LOCAL_CRATE);
5353

5454
let any_exe =
@@ -143,13 +143,16 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
143143
}
144144
}
145145

146-
fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(DefId, EntryFnType)> {
146+
fn configure_main(
147+
tcx: TyCtxt<'_>,
148+
visitor: &EntryContext<'_, '_>,
149+
) -> Option<(LocalDefId, EntryFnType)> {
147150
if let Some((hir_id, _)) = visitor.start_fn {
148-
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Start))
151+
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Start))
149152
} else if let Some((hir_id, _)) = visitor.attr_main_fn {
150-
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Main))
153+
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Main))
151154
} else if let Some((hir_id, _)) = visitor.main_fn {
152-
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Main))
155+
Some((tcx.hir().local_def_id(hir_id), EntryFnType::Main))
153156
} else {
154157
no_main_err(tcx, visitor);
155158
None
@@ -211,7 +214,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
211214
err.emit();
212215
}
213216

214-
pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(DefId, EntryFnType)> {
217+
pub fn find_entry_point(tcx: TyCtxt<'_>) -> Option<(LocalDefId, EntryFnType)> {
215218
tcx.entry_fn(LOCAL_CRATE)
216219
}
217220

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ fn check_fn<'a, 'tcx>(
14511451
// Check that the main return type implements the termination trait.
14521452
if let Some(term_id) = tcx.lang_items().termination() {
14531453
if let Some((def_id, EntryFnType::Main)) = tcx.entry_fn(LOCAL_CRATE) {
1454-
let main_id = hir.as_local_hir_id(def_id.expect_local());
1454+
let main_id = hir.as_local_hir_id(def_id);
14551455
if main_id == fn_id {
14561456
let substs = tcx.mk_substs_trait(declared_ret_ty, &[]);
14571457
let trait_ref = ty::TraitRef::new(term_id, substs);

src/librustc_typeck/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
303303

304304
fn check_for_entry_fn(tcx: TyCtxt<'_>) {
305305
match tcx.entry_fn(LOCAL_CRATE) {
306-
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id.expect_local()),
307-
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id.expect_local()),
306+
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
307+
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),
308308
_ => {}
309309
}
310310
}

0 commit comments

Comments
 (0)