Skip to content

Commit 875c6f6

Browse files
committed
Honor allow_internal_unstable for const intrinsics.
1 parent 8f24a32 commit 875c6f6

File tree

2 files changed

+10
-4
lines changed
  • compiler/rustc_const_eval/src/check_consts
  • library/core/src/intrinsics

2 files changed

+10
-4
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
853853
}
854854

855855
// Intrinsics are language primitives, not regular calls, so treat them separately.
856-
if let Some(intrinsic) = tcx.intrinsic(callee)
857-
&& intrinsic.name != sym::offset_of
858-
{
856+
if let Some(intrinsic) = tcx.intrinsic(callee) {
859857
if !tcx.is_const_fn(callee) {
860858
// Non-const intrinsic.
861859
self.check_op(ops::IntrinsicNonConst { name: intrinsic.name });
@@ -888,6 +886,15 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
888886
feature,
889887
..
890888
}) => {
889+
// We only honor `span.allows_unstable` aka `#[allow_internal_unstable]`
890+
// if the callee is safe to expose, to avoid bypassing recursive stability.
891+
// This is not ideal since it means the user sees an error, not the macro
892+
// author, but that's also the case if one forgets to set
893+
// `#[allow_internal_unstable]` in the first place.
894+
if self.span.allows_unstable(feature) && is_const_stable {
895+
return;
896+
}
897+
891898
self.check_op(ops::IntrinsicUnstable {
892899
name: intrinsic.name,
893900
feature,

library/core/src/intrinsics/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,6 @@ pub const fn align_of<T>() -> usize;
27702770
#[rustc_nounwind]
27712771
#[unstable(feature = "core_intrinsics", issue = "none")]
27722772
#[rustc_const_unstable(feature = "core_intrinsics", issue = "none")]
2773-
#[rustc_const_stable_indirect]
27742773
#[rustc_intrinsic_const_stable_indirect]
27752774
#[rustc_intrinsic]
27762775
#[lang = "offset_of"]

0 commit comments

Comments
 (0)