@@ -23,7 +23,6 @@ use rustc_span::{Span, Symbol, sym};
2323use rustc_trait_selection:: traits:: {
2424 Obligation , ObligationCause , ObligationCauseCode , ObligationCtxt ,
2525} ;
26- use smallvec:: SmallVec ;
2726use tracing:: { debug, instrument, trace} ;
2827
2928use super :: ops:: { self , NonConstOp , Status } ;
@@ -761,7 +760,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
761760 // Non-const intrinsic.
762761 self . check_op ( ops:: IntrinsicNonConst { name : intrinsic. name } ) ;
763762 }
764- Some ( ConstStability { level : ConstStabilityLevel :: Implicit , .. } ) => {
763+ Some ( ConstStability {
764+ level : ConstStabilityLevel :: ImplicitUnstable ,
765+ ..
766+ } ) => {
765767 // Intrinsic does not need a separate feature gate (we rely on the
766768 // regular stability checker). However, we have to worry about recursive
767769 // const stability.
@@ -815,7 +817,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
815817 Some ( ConstStability { level : ConstStabilityLevel :: Stable { .. } , .. } ) => {
816818 // All good.
817819 }
818- None | Some ( ConstStability { level : ConstStabilityLevel :: Implicit , .. } ) => {
820+ None
821+ | Some ( ConstStability {
822+ level : ConstStabilityLevel :: ImplicitUnstable , ..
823+ } ) => {
819824 // This doesn't need a separate const-stability check -- const-stability equals
820825 // regular stability, and regular stability is checked separately.
821826 // However, we *do* have to worry about *recursive* const stability.
@@ -838,43 +843,33 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
838843
839844 // We only honor `span.allows_unstable` aka `#[allow_internal_unstable]` if
840845 // the callee is safe to expose, to avoid bypassing recursive stability.
841- let is_allowed_unstable = |u : & rustc_attr:: Unstability | {
842- callee_safe_to_expose_on_stable
843- && ( self . span . allows_unstable ( u. feature )
844- || u. implied_by . is_some_and ( |f| self . span . allows_unstable ( f) ) )
845- } ;
846- let mut needs_check =
847- unstables. iter ( ) . filter ( |u| !is_allowed_unstable ( u) ) . peekable ( ) ;
848- if needs_check. peek ( ) . is_none ( ) {
846+ if callee_safe_to_expose_on_stable
847+ && unstables. iter ( ) . all ( |u| {
848+ self . span . allows_unstable ( u. feature )
849+ || u. implied_by . is_some_and ( |f| self . span . allows_unstable ( f) )
850+ } )
851+ {
849852 return ;
850853 }
851854
852855 // We can't use `check_op` to check whether the feature is enabled because
853856 // the logic is a bit different than elsewhere: local functions don't need
854857 // the feature gate, and there might be an "implied" gate that also suffices
855858 // to allow this.
856- let is_feature_enabled = | u : & rustc_attr :: Unstability | {
857- callee . is_local ( )
858- || tcx. features ( ) . enabled ( u. feature )
859- || u. implied_by . is_some_and ( |f| tcx. features ( ) . enabled ( f) )
860- } ;
859+ let features_enabled = callee . is_local ( )
860+ || unstables . iter ( ) . all ( |u| {
861+ tcx. features ( ) . enabled ( u. feature )
862+ || u. implied_by . is_some_and ( |f| tcx. features ( ) . enabled ( f) )
863+ } ) ;
861864 // We do *not* honor this if we are in the "danger zone": we have to enforce
862865 // recursive const-stability and the callee is not safe-to-expose. In that
863866 // case we need `check_op` to do the check.
864867 let danger_zone = !callee_safe_to_expose_on_stable
865868 && self . enforce_recursive_const_stability ( ) ;
866- let missing_features: SmallVec < [ _ ; 1 ] > = if danger_zone {
867- needs_check. map ( |u| u. into ( ) ) . collect ( )
868- } else {
869- needs_check
870- . filter ( |u| !is_feature_enabled ( u) )
871- . map ( |u| u. into ( ) )
872- . collect ( )
873- } ;
874- if !missing_features. is_empty ( ) {
869+ if danger_zone || !features_enabled {
875870 self . check_op ( ops:: FnCallUnstable {
876871 def_id : callee,
877- features : missing_features ,
872+ features : unstables . iter ( ) . map ( |u| u . into ( ) ) . collect ( ) ,
878873 reason : * reason,
879874 safe_to_expose_on_stable : callee_safe_to_expose_on_stable,
880875 } ) ;
0 commit comments