Skip to content

Commit f77658b

Browse files
committed
use opt_item_name to pattern match items with names
Signed-off-by: Miguel Guarniz <[email protected]>
1 parent 959636d commit f77658b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ impl<'tcx> TyCtxt<'tcx> {
19951995
}
19961996

19971997
/// Look up the name of a definition across crates. This does not look at HIR.
1998-
fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
1998+
pub fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
19991999
if let Some(cnum) = def_id.as_crate_root() {
20002000
Some(self.crate_name(cnum))
20012001
} else {

compiler/rustc_passes/src/entry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ fn entry_point_type(ctxt: &EntryContext<'_>, id: ItemId, at_root: bool) -> Entry
5858
} else if ctxt.tcx.sess.contains_name(attrs, sym::rustc_main) {
5959
EntryPointType::MainAttr
6060
} else {
61-
let item = ctxt.tcx.hir().item(id);
62-
if item.ident.name == sym::main {
61+
if let Some(name) = ctxt.tcx.opt_item_name(id.def_id.to_def_id())
62+
&& name == sym::main {
6363
if at_root {
6464
// This is a top-level function so can be `main`.
6565
EntryPointType::MainNamed

0 commit comments

Comments
 (0)