@@ -52,31 +52,6 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
52
52
configure_main ( tcx, & ctxt)
53
53
}
54
54
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
-
80
55
fn attr_span_by_symbol ( ctxt : & EntryContext < ' _ > , id : ItemId , sym : Symbol ) -> Option < Span > {
81
56
let attrs = ctxt. tcx . hir ( ) . attrs ( id. hir_id ( ) ) ;
82
57
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
85
60
fn find_item ( id : ItemId , ctxt : & mut EntryContext < ' _ > ) {
86
61
let at_root = ctxt. tcx . opt_local_parent ( id. owner_id . def_id ) == Some ( CRATE_DEF_ID ) ;
87
62
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 {
89
70
EntryPointType :: None => {
90
71
if let Some ( span) = attr_span_by_symbol ( ctxt, id, sym:: unix_sigpipe) {
91
72
ctxt. tcx . sess . emit_err ( AttrOnlyOnMain { span, attr : sym:: unix_sigpipe } ) ;
0 commit comments