@@ -999,14 +999,19 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
999
999
}
1000
1000
1001
1001
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
+ ) {
1010
1015
[ span1, span2, ..] => {
1011
1016
self . dcx ( )
1012
1017
. emit_err ( errors:: NoMultipleAllocErrorHandler { span2 : * span2, span1 : * span1 } ) ;
@@ -1335,29 +1340,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1335
1340
}
1336
1341
}
1337
1342
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 > {
1361
1344
struct Finder {
1362
1345
name : Symbol ,
1363
1346
spans : Vec < Span > ,
@@ -1373,7 +1356,6 @@ fn alloc_error_handler_spans(krate: &ast::Crate) -> Vec<Span> {
1373
1356
}
1374
1357
}
1375
1358
1376
- let name = Symbol :: intern ( alloc_error_handler_name ( AllocatorKind :: Global ) ) ;
1377
1359
let mut f = Finder { name, spans : Vec :: new ( ) } ;
1378
1360
visit:: walk_crate ( & mut f, krate) ;
1379
1361
f. spans
0 commit comments