@@ -999,14 +999,19 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
999999 }
10001000
10011001 fn inject_allocator_crate ( & mut self , krate : & ast:: Crate ) {
1002- self . cstore . has_global_allocator = match & * global_allocator_spans ( krate) {
1003- [ span1, span2, ..] => {
1004- self . dcx ( ) . emit_err ( errors:: NoMultipleGlobalAlloc { span2 : * span2, span1 : * span1 } ) ;
1005- true
1006- }
1007- spans => !spans. is_empty ( ) ,
1008- } ;
1009- self . cstore . has_alloc_error_handler = match & * alloc_error_handler_spans ( krate) {
1002+ self . cstore . has_global_allocator =
1003+ match & * fn_spans ( krate, Symbol :: intern ( & global_fn_name ( sym:: alloc) ) ) {
1004+ [ span1, span2, ..] => {
1005+ self . dcx ( )
1006+ . emit_err ( errors:: NoMultipleGlobalAlloc { span2 : * span2, span1 : * span1 } ) ;
1007+ true
1008+ }
1009+ spans => !spans. is_empty ( ) ,
1010+ } ;
1011+ self . cstore . has_alloc_error_handler = match & * fn_spans (
1012+ krate,
1013+ Symbol :: intern ( alloc_error_handler_name ( AllocatorKind :: Global ) ) ,
1014+ ) {
10101015 [ span1, span2, ..] => {
10111016 self . dcx ( )
10121017 . emit_err ( errors:: NoMultipleAllocErrorHandler { span2 : * span2, span1 : * span1 } ) ;
@@ -1335,29 +1340,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
13351340 }
13361341}
13371342
1338- fn global_allocator_spans ( krate : & ast:: Crate ) -> Vec < Span > {
1339- struct Finder {
1340- name : Symbol ,
1341- spans : Vec < Span > ,
1342- }
1343- impl < ' ast > visit:: Visitor < ' ast > for Finder {
1344- fn visit_item ( & mut self , item : & ' ast ast:: Item ) {
1345- if item. ident . name == self . name
1346- && attr:: contains_name ( & item. attrs , sym:: rustc_std_internal_symbol)
1347- {
1348- self . spans . push ( item. span ) ;
1349- }
1350- visit:: walk_item ( self , item)
1351- }
1352- }
1353-
1354- let name = Symbol :: intern ( & global_fn_name ( sym:: alloc) ) ;
1355- let mut f = Finder { name, spans : Vec :: new ( ) } ;
1356- visit:: walk_crate ( & mut f, krate) ;
1357- f. spans
1358- }
1359-
1360- fn alloc_error_handler_spans ( krate : & ast:: Crate ) -> Vec < Span > {
1343+ fn fn_spans ( krate : & ast:: Crate , name : Symbol ) -> Vec < Span > {
13611344 struct Finder {
13621345 name : Symbol ,
13631346 spans : Vec < Span > ,
@@ -1373,7 +1356,6 @@ fn alloc_error_handler_spans(krate: &ast::Crate) -> Vec<Span> {
13731356 }
13741357 }
13751358
1376- let name = Symbol :: intern ( alloc_error_handler_name ( AllocatorKind :: Global ) ) ;
13771359 let mut f = Finder { name, spans : Vec :: new ( ) } ;
13781360 visit:: walk_crate ( & mut f, krate) ;
13791361 f. spans
0 commit comments