@@ -736,16 +736,19 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
736736
737737 // Intrinsics are language primitives, not regular calls, so treat them separately.
738738 if let Some ( intrinsic) = tcx. intrinsic ( callee) {
739+ // We use `intrinsic.const_stable` to determine if this can be safely exposed to
740+ // stable code, rather than `const_stable_indirect`. This is to make
741+ // `#[rustc_const_stable_indirect]` an attribute that is always safe to add.
739742 match tcx. lookup_const_stability ( callee) {
740743 None => {
741744 // Non-const intrinsic.
742745 self . check_op ( ops:: IntrinsicNonConst { name : intrinsic. name } ) ;
743746 }
744- Some ( ConstStability { feature : None , const_stable_indirect , .. } ) => {
747+ Some ( ConstStability { feature : None , .. } ) => {
745748 // Intrinsic does not need a separate feature gate (we rely on the
746749 // regular stability checker). However, we have to worry about recursive
747750 // const stability.
748- if !const_stable_indirect && self . enforce_recursive_const_stability ( ) {
751+ if !intrinsic . const_stable && self . enforce_recursive_const_stability ( ) {
749752 self . dcx ( ) . emit_err ( errors:: UnmarkedIntrinsicExposed {
750753 span : self . span ,
751754 def_path : self . tcx . def_path_str ( callee) ,
@@ -755,17 +758,17 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
755758 Some ( ConstStability {
756759 feature : Some ( feature) ,
757760 level : StabilityLevel :: Unstable { .. } ,
758- const_stable_indirect,
759761 ..
760762 } ) => {
761763 self . check_op ( ops:: IntrinsicUnstable {
762764 name : intrinsic. name ,
763765 feature,
764- const_stable_indirect ,
766+ const_stable : intrinsic . const_stable ,
765767 } ) ;
766768 }
767769 Some ( ConstStability { level : StabilityLevel :: Stable { .. } , .. } ) => {
768- // All good.
770+ // All good. But ensure this is indeed a const-stable intrinsic.
771+ assert ! ( intrinsic. const_stable) ;
769772 }
770773 }
771774 // This completes the checks for intrinsics.
0 commit comments