|  | 
| 1 | 1 | use rustc_ast::attr; | 
| 2 | 2 | use rustc_ast::entry::EntryPointType; | 
| 3 | 3 | use rustc_errors::codes::*; | 
| 4 |  | -use rustc_hir::def::DefKind; | 
|  | 4 | +use rustc_hir::attrs::AttributeKind; | 
| 5 | 5 | use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; | 
| 6 |  | -use rustc_hir::{CRATE_HIR_ID, ItemId, Node}; | 
|  | 6 | +use rustc_hir::{CRATE_HIR_ID, ItemId, Node, find_attr}; | 
| 7 | 7 | use rustc_middle::query::Providers; | 
| 8 | 8 | use rustc_middle::ty::TyCtxt; | 
| 9 | 9 | use rustc_session::RemapFileNameExt; | 
| 10 | 10 | use rustc_session::config::{CrateType, EntryFnType, RemapPathScopeComponents, sigpipe}; | 
| 11 |  | -use rustc_span::{Span, Symbol, sym}; | 
|  | 11 | +use rustc_span::{Span, sym}; | 
| 12 | 12 | 
 | 
| 13 |  | -use crate::errors::{AttrOnlyInFunctions, ExternMain, MultipleRustcMain, NoMainErr}; | 
|  | 13 | +use crate::errors::{ExternMain, MultipleRustcMain, NoMainErr}; | 
| 14 | 14 | 
 | 
| 15 | 15 | struct EntryContext<'tcx> { | 
| 16 | 16 |     tcx: TyCtxt<'tcx>, | 
| @@ -44,26 +44,12 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> { | 
| 44 | 44 |     configure_main(tcx, &ctxt) | 
| 45 | 45 | } | 
| 46 | 46 | 
 | 
| 47 |  | -fn attr_span_by_symbol(ctxt: &EntryContext<'_>, id: ItemId, sym: Symbol) -> Option<Span> { | 
| 48 |  | -    let attrs = ctxt.tcx.hir_attrs(id.hir_id()); | 
| 49 |  | -    attr::find_by_name(attrs, sym).map(|attr| attr.span()) | 
| 50 |  | -} | 
| 51 |  | - | 
| 52 | 47 | fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) { | 
| 53 |  | -    if !matches!(ctxt.tcx.def_kind(id.owner_id), DefKind::Fn) { | 
| 54 |  | -        for attr in [sym::rustc_main] { | 
| 55 |  | -            if let Some(span) = attr_span_by_symbol(ctxt, id, attr) { | 
| 56 |  | -                ctxt.tcx.dcx().emit_err(AttrOnlyInFunctions { span, attr }); | 
| 57 |  | -            } | 
| 58 |  | -        } | 
| 59 |  | -        return; | 
| 60 |  | -    } | 
| 61 |  | - | 
| 62 | 48 |     let at_root = ctxt.tcx.opt_local_parent(id.owner_id.def_id) == Some(CRATE_DEF_ID); | 
| 63 | 49 | 
 | 
| 64 | 50 |     let attrs = ctxt.tcx.hir_attrs(id.hir_id()); | 
| 65 | 51 |     let entry_point_type = rustc_ast::entry::entry_point_type( | 
| 66 |  | -        attrs, | 
|  | 52 | +        find_attr!(attrs, AttributeKind::RustcMain), | 
| 67 | 53 |         at_root, | 
| 68 | 54 |         ctxt.tcx.opt_item_name(id.owner_id.to_def_id()), | 
| 69 | 55 |     ); | 
|  | 
0 commit comments