@@ -702,6 +702,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
702
702
// We use `intrinsic.const_stable` to determine if this can be safely exposed to
703
703
// stable code, rather than `const_stable_indirect`. This is to make
704
704
// `#[rustc_const_stable_indirect]` an attribute that is always safe to add.
705
+ // We also ask is_safe_to_expose_on_stable_const_fn; this determines whether the intrinsic
706
+ // fallback body is safe to expose on stable.
707
+ let is_const_stable = intrinsic. const_stable
708
+ || ( !intrinsic. must_be_overridden
709
+ && is_safe_to_expose_on_stable_const_fn ( tcx, callee) ) ;
705
710
match tcx. lookup_const_stability ( callee) {
706
711
None => {
707
712
// Non-const intrinsic.
@@ -711,7 +716,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
711
716
// Intrinsic does not need a separate feature gate (we rely on the
712
717
// regular stability checker). However, we have to worry about recursive
713
718
// const stability.
714
- if !intrinsic . const_stable && self . enforce_recursive_const_stability ( ) {
719
+ if !is_const_stable && self . enforce_recursive_const_stability ( ) {
715
720
self . dcx ( ) . emit_err ( errors:: UnmarkedIntrinsicExposed {
716
721
span : self . span ,
717
722
def_path : self . tcx . def_path_str ( callee) ,
@@ -726,12 +731,14 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
726
731
self . check_op ( ops:: IntrinsicUnstable {
727
732
name : intrinsic. name ,
728
733
feature,
729
- const_stable : intrinsic . const_stable ,
734
+ const_stable : is_const_stable ,
730
735
} ) ;
731
736
}
732
737
Some ( ConstStability { level : StabilityLevel :: Stable { .. } , .. } ) => {
733
- // All good. But ensure this is indeed a const-stable intrinsic.
734
- assert ! ( intrinsic. const_stable) ;
738
+ // All good. Note that a `#[rustc_const_stable]` intrinsic (meaning it
739
+ // can be *directly* invoked from stable const code) does not always
740
+ // have the `#[rustc_const_stable_intrinsic]` attribute (which controls
741
+ // exposing an intrinsic indirectly); we accept this call anyway.
735
742
}
736
743
}
737
744
// This completes the checks for intrinsics.
0 commit comments