11use rustc_ast:: entry:: EntryPointType ;
22use rustc_errors:: struct_span_err;
3- use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID , CRATE_DEF_INDEX , LOCAL_CRATE } ;
3+ use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID , CRATE_DEF_INDEX , LOCAL_CRATE } ;
44use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
5- use rustc_hir:: { ForeignItem , HirId , ImplItem , Item , ItemKind , Node , TraitItem , CRATE_HIR_ID } ;
5+ use rustc_hir:: { ForeignItem , ImplItem , Item , ItemKind , Node , TraitItem , CRATE_HIR_ID } ;
66use rustc_middle:: hir:: map:: Map ;
77use rustc_middle:: ty:: query:: Providers ;
88use rustc_middle:: ty:: TyCtxt ;
@@ -18,14 +18,14 @@ struct EntryContext<'a, 'tcx> {
1818 map : Map < ' tcx > ,
1919
2020 /// The function that has attribute named `main`.
21- attr_main_fn : Option < ( HirId , Span ) > ,
21+ attr_main_fn : Option < ( LocalDefId , Span ) > ,
2222
2323 /// The function that has the attribute 'start' on it.
24- start_fn : Option < ( HirId , Span ) > ,
24+ start_fn : Option < ( LocalDefId , Span ) > ,
2525
2626 /// The functions that one might think are `main` but aren't, e.g.
2727 /// main functions not defined at the top level. For diagnostics.
28- non_main_fns : Vec < ( HirId , Span ) > ,
28+ non_main_fns : Vec < Span > ,
2929}
3030
3131impl < ' a , ' tcx > ItemLikeVisitor < ' tcx > for EntryContext < ' a , ' tcx > {
@@ -112,11 +112,11 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
112112 }
113113 EntryPointType :: MainNamed => ( ) ,
114114 EntryPointType :: OtherMain => {
115- ctxt. non_main_fns . push ( ( item. hir_id ( ) , item . span ) ) ;
115+ ctxt. non_main_fns . push ( item. span ) ;
116116 }
117117 EntryPointType :: MainAttr => {
118118 if ctxt. attr_main_fn . is_none ( ) {
119- ctxt. attr_main_fn = Some ( ( item. hir_id ( ) , item. span ) ) ;
119+ ctxt. attr_main_fn = Some ( ( item. def_id , item. span ) ) ;
120120 } else {
121121 struct_span_err ! (
122122 ctxt. session,
@@ -131,7 +131,7 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
131131 }
132132 EntryPointType :: Start => {
133133 if ctxt. start_fn . is_none ( ) {
134- ctxt. start_fn = Some ( ( item. hir_id ( ) , item. span ) ) ;
134+ ctxt. start_fn = Some ( ( item. def_id , item. span ) ) ;
135135 } else {
136136 struct_span_err ! ( ctxt. session, item. span, E0138 , "multiple `start` functions" )
137137 . span_label ( ctxt. start_fn . unwrap ( ) . 1 , "previous `#[start]` function here" )
@@ -143,16 +143,16 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
143143}
144144
145145fn configure_main ( tcx : TyCtxt < ' _ > , visitor : & EntryContext < ' _ , ' _ > ) -> Option < ( DefId , EntryFnType ) > {
146- if let Some ( ( hir_id , _) ) = visitor. start_fn {
147- Some ( ( tcx . hir ( ) . local_def_id ( hir_id ) . to_def_id ( ) , EntryFnType :: Start ) )
148- } else if let Some ( ( hir_id , _) ) = visitor. attr_main_fn {
149- Some ( ( tcx . hir ( ) . local_def_id ( hir_id ) . to_def_id ( ) , EntryFnType :: Main ) )
146+ if let Some ( ( def_id , _) ) = visitor. start_fn {
147+ Some ( ( def_id . to_def_id ( ) , EntryFnType :: Start ) )
148+ } else if let Some ( ( def_id , _) ) = visitor. attr_main_fn {
149+ Some ( ( def_id . to_def_id ( ) , EntryFnType :: Main ) )
150150 } else {
151151 if let Some ( main_def) = tcx. resolutions ( ( ) ) . main_def {
152152 if let Some ( def_id) = main_def. opt_fn_def_id ( ) {
153153 // non-local main imports are handled below
154- if def_id. is_local ( ) {
155- let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id. expect_local ( ) ) ;
154+ if let Some ( def_id) = def_id . as_local ( ) {
155+ let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
156156 if matches ! ( tcx. hir( ) . find( hir_id) , Some ( Node :: ForeignItem ( _) ) ) {
157157 tcx. sess
158158 . struct_span_err (
@@ -201,7 +201,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
201201 ) ;
202202 let filename = & tcx. sess . local_crate_source_file ;
203203 let note = if !visitor. non_main_fns . is_empty ( ) {
204- for & ( _ , span) in & visitor. non_main_fns {
204+ for & span in & visitor. non_main_fns {
205205 err. span_note ( span, "here is a function named `main`" ) ;
206206 }
207207 err. note ( "you have one or more functions named `main` not defined at the crate level" ) ;
0 commit comments