@@ -1032,14 +1032,19 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
10321032 }
10331033
10341034 fn inject_allocator_crate ( & mut self , krate : & ast:: Crate ) {
1035- self . cstore . has_global_allocator = match & * global_allocator_spans ( krate) {
1036- [ span1, span2, ..] => {
1037- self . dcx ( ) . emit_err ( errors:: NoMultipleGlobalAlloc { span2 : * span2, span1 : * span1 } ) ;
1038- true
1039- }
1040- spans => !spans. is_empty ( ) ,
1041- } ;
1042- self . cstore . has_alloc_error_handler = match & * alloc_error_handler_spans ( krate) {
1035+ self . cstore . has_global_allocator =
1036+ match & * fn_spans ( krate, Symbol :: intern ( & global_fn_name ( sym:: alloc) ) ) {
1037+ [ span1, span2, ..] => {
1038+ self . dcx ( )
1039+ . emit_err ( errors:: NoMultipleGlobalAlloc { span2 : * span2, span1 : * span1 } ) ;
1040+ true
1041+ }
1042+ spans => !spans. is_empty ( ) ,
1043+ } ;
1044+ self . cstore . has_alloc_error_handler = match & * fn_spans (
1045+ krate,
1046+ Symbol :: intern ( alloc_error_handler_name ( AllocatorKind :: Global ) ) ,
1047+ ) {
10431048 [ span1, span2, ..] => {
10441049 self . dcx ( )
10451050 . emit_err ( errors:: NoMultipleAllocErrorHandler { span2 : * span2, span1 : * span1 } ) ;
@@ -1368,29 +1373,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
13681373 }
13691374}
13701375
1371- fn global_allocator_spans ( krate : & ast:: Crate ) -> Vec < Span > {
1372- struct Finder {
1373- name : Symbol ,
1374- spans : Vec < Span > ,
1375- }
1376- impl < ' ast > visit:: Visitor < ' ast > for Finder {
1377- fn visit_item ( & mut self , item : & ' ast ast:: Item ) {
1378- if item. ident . name == self . name
1379- && attr:: contains_name ( & item. attrs , sym:: rustc_std_internal_symbol)
1380- {
1381- self . spans . push ( item. span ) ;
1382- }
1383- visit:: walk_item ( self , item)
1384- }
1385- }
1386-
1387- let name = Symbol :: intern ( & global_fn_name ( sym:: alloc) ) ;
1388- let mut f = Finder { name, spans : Vec :: new ( ) } ;
1389- visit:: walk_crate ( & mut f, krate) ;
1390- f. spans
1391- }
1392-
1393- fn alloc_error_handler_spans ( krate : & ast:: Crate ) -> Vec < Span > {
1376+ fn fn_spans ( krate : & ast:: Crate , name : Symbol ) -> Vec < Span > {
13941377 struct Finder {
13951378 name : Symbol ,
13961379 spans : Vec < Span > ,
@@ -1406,7 +1389,6 @@ fn alloc_error_handler_spans(krate: &ast::Crate) -> Vec<Span> {
14061389 }
14071390 }
14081391
1409- let name = Symbol :: intern ( alloc_error_handler_name ( AllocatorKind :: Global ) ) ;
14101392 let mut f = Finder { name, spans : Vec :: new ( ) } ;
14111393 visit:: walk_crate ( & mut f, krate) ;
14121394 f. spans
0 commit comments