@@ -52,31 +52,6 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
5252 configure_main ( tcx, & ctxt)
5353}
5454
55- // Beware, this is duplicated in `librustc_builtin_macros/test_harness.rs`
56- // (with `ast::Item`), so make sure to keep them in sync.
57- // A small optimization was added so that hir::Item is fetched only when needed.
58- // An equivalent optimization was not applied to the duplicated code in test_harness.rs.
59- fn entry_point_type ( ctxt : & EntryContext < ' _ > , id : ItemId , at_root : bool ) -> EntryPointType {
60- let attrs = ctxt. tcx . hir ( ) . attrs ( id. hir_id ( ) ) ;
61- if attr:: contains_name ( attrs, sym:: start) {
62- EntryPointType :: Start
63- } else if attr:: contains_name ( attrs, sym:: rustc_main) {
64- EntryPointType :: RustcMainAttr
65- } else {
66- if let Some ( name) = ctxt. tcx . opt_item_name ( id. owner_id . to_def_id ( ) )
67- && name == sym:: main {
68- if at_root {
69- // This is a top-level function so can be `main`.
70- EntryPointType :: MainNamed
71- } else {
72- EntryPointType :: OtherMain
73- }
74- } else {
75- EntryPointType :: None
76- }
77- }
78- }
79-
8055fn attr_span_by_symbol ( ctxt : & EntryContext < ' _ > , id : ItemId , sym : Symbol ) -> Option < Span > {
8156 let attrs = ctxt. tcx . hir ( ) . attrs ( id. hir_id ( ) ) ;
8257 attr:: find_by_name ( attrs, sym) . map ( |attr| attr. span )
@@ -85,7 +60,13 @@ fn attr_span_by_symbol(ctxt: &EntryContext<'_>, id: ItemId, sym: Symbol) -> Opti
8560fn find_item ( id : ItemId , ctxt : & mut EntryContext < ' _ > ) {
8661 let at_root = ctxt. tcx . opt_local_parent ( id. owner_id . def_id ) == Some ( CRATE_DEF_ID ) ;
8762
88- match entry_point_type ( ctxt, id, at_root) {
63+ let attrs = ctxt. tcx . hir ( ) . attrs ( id. hir_id ( ) ) ;
64+ let entry_point_type = rustc_ast:: entry:: entry_point_type (
65+ attrs,
66+ at_root,
67+ ctxt. tcx . opt_item_name ( id. owner_id . to_def_id ( ) ) ,
68+ ) ;
69+ match entry_point_type {
8970 EntryPointType :: None => {
9071 if let Some ( span) = attr_span_by_symbol ( ctxt, id, sym:: unix_sigpipe) {
9172 ctxt. tcx . sess . emit_err ( AttrOnlyOnMain { span, attr : sym:: unix_sigpipe } ) ;
0 commit comments