@@ -12,7 +12,7 @@ use rustc_errors::{codes::*, struct_span_code_err, DiagnosticMessage};
1212use rustc_hir as hir;
1313use rustc_middle:: traits:: { ObligationCause , ObligationCauseCode } ;
1414use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
15- use rustc_span:: symbol:: { kw, sym, Symbol } ;
15+ use rustc_span:: symbol:: { kw, sym} ;
1616use rustc_target:: spec:: abi:: Abi ;
1717
1818fn equate_intrinsic_type < ' tcx > (
@@ -132,7 +132,17 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
132132/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
133133/// and in `library/core/src/intrinsics.rs`.
134134pub fn check_intrinsic_type ( tcx : TyCtxt < ' _ > , it : & hir:: ForeignItem < ' _ > ) {
135- let param = |n| Ty :: new_param ( tcx, n, Symbol :: intern ( & format ! ( "P{n}" ) ) ) ;
135+ let generics = tcx. generics_of ( it. owner_id ) ;
136+ let param = |n| {
137+ if let Some ( & ty:: GenericParamDef {
138+ name, kind : ty:: GenericParamDefKind :: Type { .. } , ..
139+ } ) = generics. opt_param_at ( n as usize , tcx)
140+ {
141+ Ty :: new_param ( tcx, n, name)
142+ } else {
143+ Ty :: new_error_with_message ( tcx, tcx. def_span ( it. owner_id ) , "expected param" )
144+ }
145+ } ;
136146 let intrinsic_id = it. owner_id . to_def_id ( ) ;
137147 let intrinsic_name = tcx. item_name ( intrinsic_id) ;
138148 let name_str = intrinsic_name. as_str ( ) ;
@@ -475,9 +485,16 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
475485
476486/// Type-check `extern "platform-intrinsic" { ... }` functions.
477487pub fn check_platform_intrinsic_type ( tcx : TyCtxt < ' _ > , it : & hir:: ForeignItem < ' _ > ) {
488+ let generics = tcx. generics_of ( it. owner_id ) ;
478489 let param = |n| {
479- let name = Symbol :: intern ( & format ! ( "P{n}" ) ) ;
480- Ty :: new_param ( tcx, n, name)
490+ if let Some ( & ty:: GenericParamDef {
491+ name, kind : ty:: GenericParamDefKind :: Type { .. } , ..
492+ } ) = generics. opt_param_at ( n as usize , tcx)
493+ {
494+ Ty :: new_param ( tcx, n, name)
495+ } else {
496+ Ty :: new_error_with_message ( tcx, tcx. def_span ( it. owner_id ) , "expected param" )
497+ }
481498 } ;
482499
483500 let name = it. ident . name ;
0 commit comments