about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMiguel Guarniz <mi9uel9@gmail.com>2022-05-12 14:03:21 -0400
committerMiguel Guarniz <mi9uel9@gmail.com>2022-05-14 11:02:14 -0400
commitf77658b470deb558ef3a270ca154a8afad230600 (patch)
tree7cd9e5a4d9fb77e46a3dcc92539f0e4135cc1240
parent959636d53126fdc33452759dcba44d12a980674b (diff)
downloadrust-f77658b470deb558ef3a270ca154a8afad230600.tar.gz
rust-f77658b470deb558ef3a270ca154a8afad230600.zip
use opt_item_name to pattern match items with names
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs2
-rw-r--r--compiler/rustc_passes/src/entry.rs4
2 files changed, 3 insertions, 3 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index c4e0ebdc638..c62b6f7e429 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -1995,7 +1995,7 @@ impl<'tcx> TyCtxt<'tcx> {
     }
 
     /// Look up the name of a definition across crates. This does not look at HIR.
-    fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
+    pub fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
         if let Some(cnum) = def_id.as_crate_root() {
             Some(self.crate_name(cnum))
         } else {
diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs
index 747332e6070..b90d44e2af5 100644
--- a/compiler/rustc_passes/src/entry.rs
+++ b/compiler/rustc_passes/src/entry.rs
@@ -58,8 +58,8 @@ fn entry_point_type(ctxt: &EntryContext<'_>, id: ItemId, at_root: bool) -> Entry
     } else if ctxt.tcx.sess.contains_name(attrs, sym::rustc_main) {
         EntryPointType::MainAttr
     } else {
-        let item = ctxt.tcx.hir().item(id);
-        if item.ident.name == sym::main {
+        if let Some(name) = ctxt.tcx.opt_item_name(id.def_id.to_def_id())
+            && name == sym::main {
             if at_root {
                 // This is a top-level function so can be `main`.
                 EntryPointType::MainNamed