@@ -702,6 +702,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
702702 // We use `intrinsic.const_stable` to determine if this can be safely exposed to
703703 // stable code, rather than `const_stable_indirect`. This is to make
704704 // `#[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) ) ;
705710 match tcx. lookup_const_stability ( callee) {
706711 None => {
707712 // Non-const intrinsic.
@@ -711,7 +716,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
711716 // Intrinsic does not need a separate feature gate (we rely on the
712717 // regular stability checker). However, we have to worry about recursive
713718 // const stability.
714- if !intrinsic . const_stable && self . enforce_recursive_const_stability ( ) {
719+ if !is_const_stable && self . enforce_recursive_const_stability ( ) {
715720 self . dcx ( ) . emit_err ( errors:: UnmarkedIntrinsicExposed {
716721 span : self . span ,
717722 def_path : self . tcx . def_path_str ( callee) ,
@@ -726,12 +731,14 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
726731 self . check_op ( ops:: IntrinsicUnstable {
727732 name : intrinsic. name ,
728733 feature,
729- const_stable : intrinsic . const_stable ,
734+ const_stable : is_const_stable ,
730735 } ) ;
731736 }
732737 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.
735742 }
736743 }
737744 // This completes the checks for intrinsics.
0 commit comments