@@ -2,11 +2,10 @@ use crate::hir::map as hir_map;
22use crate :: hir:: def_id:: { CrateNum , CRATE_DEF_INDEX , DefId , LOCAL_CRATE } ;
33use crate :: session:: { config, Session } ;
44use crate :: session:: config:: EntryFnType ;
5- use syntax:: ast:: NodeId ;
65use syntax:: attr;
76use syntax:: entry:: EntryPointType ;
87use syntax_pos:: Span ;
9- use crate :: hir:: { Item , ItemKind , ImplItem , TraitItem } ;
8+ use crate :: hir:: { HirId , Item , ItemKind , ImplItem , TraitItem } ;
109use crate :: hir:: itemlikevisit:: ItemLikeVisitor ;
1110use crate :: ty:: TyCtxt ;
1211use crate :: ty:: query:: Providers ;
@@ -17,22 +16,22 @@ struct EntryContext<'a, 'tcx: 'a> {
1716 map : & ' a hir_map:: Map < ' tcx > ,
1817
1918 // The top-level function called 'main'
20- main_fn : Option < ( NodeId , Span ) > ,
19+ main_fn : Option < ( HirId , Span ) > ,
2120
2221 // The function that has attribute named 'main'
23- attr_main_fn : Option < ( NodeId , Span ) > ,
22+ attr_main_fn : Option < ( HirId , Span ) > ,
2423
2524 // The function that has the attribute 'start' on it
26- start_fn : Option < ( NodeId , Span ) > ,
25+ start_fn : Option < ( HirId , Span ) > ,
2726
2827 // The functions that one might think are 'main' but aren't, e.g.
2928 // main functions not defined at the top level. For diagnostics.
30- non_main_fns : Vec < ( NodeId , Span ) > ,
29+ non_main_fns : Vec < ( HirId , Span ) > ,
3130}
3231
3332impl < ' a , ' tcx > ItemLikeVisitor < ' tcx > for EntryContext < ' a , ' tcx > {
3433 fn visit_item ( & mut self , item : & ' tcx Item ) {
35- let def_id = self . map . local_def_id ( item. id ) ;
34+ let def_id = self . map . local_def_id_from_hir_id ( item. hir_id ) ;
3635 let def_key = self . map . def_key ( def_id) ;
3736 let at_root = def_key. parent == Some ( CRATE_DEF_INDEX ) ;
3837 find_item ( item, self , at_root) ;
@@ -106,18 +105,18 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
106105 match entry_point_type ( item, at_root) {
107106 EntryPointType :: MainNamed => {
108107 if ctxt. main_fn . is_none ( ) {
109- ctxt. main_fn = Some ( ( item. id , item. span ) ) ;
108+ ctxt. main_fn = Some ( ( item. hir_id , item. span ) ) ;
110109 } else {
111110 span_err ! ( ctxt. session, item. span, E0136 ,
112111 "multiple 'main' functions" ) ;
113112 }
114113 } ,
115114 EntryPointType :: OtherMain => {
116- ctxt. non_main_fns . push ( ( item. id , item. span ) ) ;
115+ ctxt. non_main_fns . push ( ( item. hir_id , item. span ) ) ;
117116 } ,
118117 EntryPointType :: MainAttr => {
119118 if ctxt. attr_main_fn . is_none ( ) {
120- ctxt. attr_main_fn = Some ( ( item. id , item. span ) ) ;
119+ ctxt. attr_main_fn = Some ( ( item. hir_id , item. span ) ) ;
121120 } else {
122121 struct_span_err ! ( ctxt. session, item. span, E0137 ,
123122 "multiple functions with a #[main] attribute" )
@@ -128,7 +127,7 @@ fn find_item(item: &Item, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
128127 } ,
129128 EntryPointType :: Start => {
130129 if ctxt. start_fn . is_none ( ) {
131- ctxt. start_fn = Some ( ( item. id , item. span ) ) ;
130+ ctxt. start_fn = Some ( ( item. hir_id , item. span ) ) ;
132131 } else {
133132 struct_span_err ! ( ctxt. session, item. span, E0138 , "multiple 'start' functions" )
134133 . span_label ( ctxt. start_fn . unwrap ( ) . 1 , "previous `start` function here" )
@@ -144,12 +143,12 @@ fn configure_main(
144143 tcx : TyCtxt < ' _ , ' _ , ' _ > ,
145144 visitor : & EntryContext < ' _ , ' _ > ,
146145) -> Option < ( DefId , EntryFnType ) > {
147- if let Some ( ( node_id , _) ) = visitor. start_fn {
148- Some ( ( tcx. hir ( ) . local_def_id ( node_id ) , EntryFnType :: Start ) )
149- } else if let Some ( ( node_id , _) ) = visitor. attr_main_fn {
150- Some ( ( tcx. hir ( ) . local_def_id ( node_id ) , EntryFnType :: Main ) )
151- } else if let Some ( ( node_id , _) ) = visitor. main_fn {
152- Some ( ( tcx. hir ( ) . local_def_id ( node_id ) , EntryFnType :: Main ) )
146+ if let Some ( ( hir_id , _) ) = visitor. start_fn {
147+ Some ( ( tcx. hir ( ) . local_def_id_from_hir_id ( hir_id ) , EntryFnType :: Start ) )
148+ } else if let Some ( ( hir_id , _) ) = visitor. attr_main_fn {
149+ Some ( ( tcx. hir ( ) . local_def_id_from_hir_id ( hir_id ) , EntryFnType :: Main ) )
150+ } else if let Some ( ( hir_id , _) ) = visitor. main_fn {
151+ Some ( ( tcx. hir ( ) . local_def_id_from_hir_id ( hir_id ) , EntryFnType :: Main ) )
153152 } else {
154153 // No main function
155154 let mut err = struct_err ! ( tcx. sess, E0601 ,
0 commit comments