Skip to content

Commit dd31197

Browse files
committed
Make check_intrinsic_type not require ForeignItems anymore
1 parent d5f1215 commit dd31197

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,18 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
533533
match abi {
534534
Abi::RustIntrinsic => {
535535
for item in items {
536-
let item = tcx.hir().foreign_item(item.id);
537-
intrinsic::check_intrinsic_type(tcx, item);
536+
intrinsic::check_intrinsic_type(tcx, item.id.owner_id.def_id, item.span);
538537
}
539538
}
540539

541540
Abi::PlatformIntrinsic => {
542541
for item in items {
543-
let item = tcx.hir().foreign_item(item.id);
544-
intrinsic::check_platform_intrinsic_type(tcx, item);
542+
intrinsic::check_platform_intrinsic_type(
543+
tcx,
544+
item.id.owner_id.def_id,
545+
item.span,
546+
item.ident.name,
547+
);
545548
}
546549
}
547550

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
135135

136136
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
137137
/// and in `library/core/src/intrinsics.rs`.
138-
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
138+
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId, span: Span) {
139139
let param = |n| Ty::new_param(tcx, n, Symbol::intern(&format!("P{n}")));
140-
let intrinsic_id = it.owner_id.def_id;
141140
let intrinsic_name = tcx.item_name(intrinsic_id.into());
142141
let name_str = intrinsic_name.as_str();
143142

@@ -180,7 +179,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
180179
| "umin" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], param(0)),
181180
"fence" | "singlethreadfence" => (0, Vec::new(), Ty::new_unit(tcx)),
182181
op => {
183-
tcx.dcx().emit_err(UnrecognizedAtomicOperation { span: it.span, op });
182+
tcx.dcx().emit_err(UnrecognizedAtomicOperation { span, op });
184183
return;
185184
}
186185
};
@@ -466,26 +465,29 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
466465
}
467466

468467
other => {
469-
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span: it.span, name: other });
468+
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other });
470469
return;
471470
}
472471
};
473472
(n_tps, 0, inputs, output, unsafety)
474473
};
475474
let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, Abi::RustIntrinsic);
476475
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
477-
equate_intrinsic_type(tcx, it.span, intrinsic_id, n_tps, n_lts, 0, sig)
476+
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, n_lts, 0, sig)
478477
}
479478

480479
/// Type-check `extern "platform-intrinsic" { ... }` functions.
481-
pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
480+
pub fn check_platform_intrinsic_type(
481+
tcx: TyCtxt<'_>,
482+
intrinsic_id: LocalDefId,
483+
span: Span,
484+
name: Symbol,
485+
) {
482486
let param = |n| {
483487
let name = Symbol::intern(&format!("P{n}"));
484488
Ty::new_param(tcx, n, name)
485489
};
486490

487-
let name = it.ident.name;
488-
489491
let (n_tps, n_cts, inputs, output) = match name {
490492
sym::simd_eq | sym::simd_ne | sym::simd_lt | sym::simd_le | sym::simd_gt | sym::simd_ge => {
491493
(2, 0, vec![param(0), param(0)], param(1))
@@ -558,12 +560,12 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
558560
sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)),
559561
_ => {
560562
let msg = format!("unrecognized platform-specific intrinsic function: `{name}`");
561-
tcx.dcx().span_err(it.span, msg);
563+
tcx.dcx().span_err(span, msg);
562564
return;
563565
}
564566
};
565567

566568
let sig = tcx.mk_fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic);
567569
let sig = ty::Binder::dummy(sig);
568-
equate_intrinsic_type(tcx, it.span, it.owner_id.def_id, n_tps, 0, n_cts, sig)
570+
equate_intrinsic_type(tcx, span, intrinsic_id, n_tps, 0, n_cts, sig)
569571
}

0 commit comments

Comments
 (0)