@@ -13,7 +13,7 @@ use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
13
13
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
14
14
use rustc_span:: def_id:: LocalDefId ;
15
15
use rustc_span:: symbol:: { kw, sym} ;
16
- use rustc_span:: Span ;
16
+ use rustc_span:: { Span , Symbol } ;
17
17
use rustc_target:: spec:: abi:: Abi ;
18
18
19
19
fn equate_intrinsic_type < ' tcx > (
@@ -136,19 +136,18 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
136
136
137
137
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
138
138
/// and in `library/core/src/intrinsics.rs`.
139
- pub fn check_intrinsic_type ( tcx : TyCtxt < ' _ > , it : & hir :: ForeignItem < ' _ > ) {
140
- let generics = tcx. generics_of ( it . owner_id ) ;
139
+ pub fn check_intrinsic_type ( tcx : TyCtxt < ' _ > , intrinsic_id : LocalDefId , span : Span ) {
140
+ let generics = tcx. generics_of ( intrinsic_id ) ;
141
141
let param = |n| {
142
142
if let Some ( & ty:: GenericParamDef {
143
143
name, kind : ty:: GenericParamDefKind :: Type { .. } , ..
144
144
} ) = generics. opt_param_at ( n as usize , tcx)
145
145
{
146
146
Ty :: new_param ( tcx, n, name)
147
147
} else {
148
- Ty :: new_error_with_message ( tcx, tcx . def_span ( it . owner_id ) , "expected param" )
148
+ Ty :: new_error_with_message ( tcx, span , "expected param" )
149
149
}
150
150
} ;
151
- let intrinsic_id = it. owner_id . def_id ;
152
151
let intrinsic_name = tcx. item_name ( intrinsic_id. into ( ) ) ;
153
152
let name_str = intrinsic_name. as_str ( ) ;
154
153
@@ -191,7 +190,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
191
190
| "umin" => ( 1 , vec ! [ Ty :: new_mut_ptr( tcx, param( 0 ) ) , param( 0 ) ] , param ( 0 ) ) ,
192
191
"fence" | "singlethreadfence" => ( 0 , Vec :: new ( ) , Ty :: new_unit ( tcx) ) ,
193
192
op => {
194
- tcx. dcx ( ) . emit_err ( UnrecognizedAtomicOperation { span : it . span , op } ) ;
193
+ tcx. dcx ( ) . emit_err ( UnrecognizedAtomicOperation { span, op } ) ;
195
194
return ;
196
195
}
197
196
} ;
@@ -479,33 +478,36 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
479
478
sym:: debug_assertions => ( 0 , Vec :: new ( ) , tcx. types . bool ) ,
480
479
481
480
other => {
482
- tcx. dcx ( ) . emit_err ( UnrecognizedIntrinsicFunction { span : it . span , name : other } ) ;
481
+ tcx. dcx ( ) . emit_err ( UnrecognizedIntrinsicFunction { span, name : other } ) ;
483
482
return ;
484
483
}
485
484
} ;
486
485
( n_tps, 0 , inputs, output, unsafety)
487
486
} ;
488
487
let sig = tcx. mk_fn_sig ( inputs, output, false , unsafety, Abi :: RustIntrinsic ) ;
489
488
let sig = ty:: Binder :: bind_with_vars ( sig, bound_vars) ;
490
- equate_intrinsic_type ( tcx, it . span , intrinsic_id, n_tps, n_lts, 0 , sig)
489
+ equate_intrinsic_type ( tcx, span, intrinsic_id, n_tps, n_lts, 0 , sig)
491
490
}
492
491
493
492
/// Type-check `extern "platform-intrinsic" { ... }` functions.
494
- pub fn check_platform_intrinsic_type ( tcx : TyCtxt < ' _ > , it : & hir:: ForeignItem < ' _ > ) {
495
- let generics = tcx. generics_of ( it. owner_id ) ;
493
+ pub fn check_platform_intrinsic_type (
494
+ tcx : TyCtxt < ' _ > ,
495
+ intrinsic_id : LocalDefId ,
496
+ span : Span ,
497
+ name : Symbol ,
498
+ ) {
499
+ let generics = tcx. generics_of ( intrinsic_id) ;
496
500
let param = |n| {
497
501
if let Some ( & ty:: GenericParamDef {
498
502
name, kind : ty:: GenericParamDefKind :: Type { .. } , ..
499
503
} ) = generics. opt_param_at ( n as usize , tcx)
500
504
{
501
505
Ty :: new_param ( tcx, n, name)
502
506
} else {
503
- Ty :: new_error_with_message ( tcx, tcx . def_span ( it . owner_id ) , "expected param" )
507
+ Ty :: new_error_with_message ( tcx, span , "expected param" )
504
508
}
505
509
} ;
506
510
507
- let name = it. ident . name ;
508
-
509
511
let ( n_tps, n_cts, inputs, output) = match name {
510
512
sym:: simd_eq | sym:: simd_ne | sym:: simd_lt | sym:: simd_le | sym:: simd_gt | sym:: simd_ge => {
511
513
( 2 , 0 , vec ! [ param( 0 ) , param( 0 ) ] , param ( 1 ) )
@@ -578,12 +580,12 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
578
580
sym:: simd_shuffle_generic => ( 2 , 1 , vec ! [ param( 0 ) , param( 0 ) ] , param ( 1 ) ) ,
579
581
_ => {
580
582
let msg = format ! ( "unrecognized platform-specific intrinsic function: `{name}`" ) ;
581
- tcx. dcx ( ) . span_err ( it . span , msg) ;
583
+ tcx. dcx ( ) . span_err ( span, msg) ;
582
584
return ;
583
585
}
584
586
} ;
585
587
586
588
let sig = tcx. mk_fn_sig ( inputs, output, false , hir:: Unsafety :: Unsafe , Abi :: PlatformIntrinsic ) ;
587
589
let sig = ty:: Binder :: dummy ( sig) ;
588
- equate_intrinsic_type ( tcx, it . span , it . owner_id . def_id , n_tps, 0 , n_cts, sig)
590
+ equate_intrinsic_type ( tcx, span, intrinsic_id , n_tps, 0 , n_cts, sig)
589
591
}
0 commit comments