@@ -1032,14 +1032,19 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1032
1032
}
1033
1033
1034
1034
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
+ ) {
1043
1048
[ span1, span2, ..] => {
1044
1049
self . dcx ( )
1045
1050
. emit_err ( errors:: NoMultipleAllocErrorHandler { span2 : * span2, span1 : * span1 } ) ;
@@ -1368,29 +1373,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1368
1373
}
1369
1374
}
1370
1375
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 > {
1394
1377
struct Finder {
1395
1378
name : Symbol ,
1396
1379
spans : Vec < Span > ,
@@ -1406,7 +1389,6 @@ fn alloc_error_handler_spans(krate: &ast::Crate) -> Vec<Span> {
1406
1389
}
1407
1390
}
1408
1391
1409
- let name = Symbol :: intern ( alloc_error_handler_name ( AllocatorKind :: Global ) ) ;
1410
1392
let mut f = Finder { name, spans : Vec :: new ( ) } ;
1411
1393
visit:: walk_crate ( & mut f, krate) ;
1412
1394
f. spans
0 commit comments