@@ -23,7 +23,6 @@ use rustc_span::{Span, Symbol, sym};
23
23
use rustc_trait_selection:: traits:: {
24
24
Obligation , ObligationCause , ObligationCauseCode , ObligationCtxt ,
25
25
} ;
26
- use smallvec:: SmallVec ;
27
26
use tracing:: { debug, instrument, trace} ;
28
27
29
28
use super :: ops:: { self , NonConstOp , Status } ;
@@ -761,7 +760,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
761
760
// Non-const intrinsic.
762
761
self . check_op ( ops:: IntrinsicNonConst { name : intrinsic. name } ) ;
763
762
}
764
- Some ( ConstStability { level : ConstStabilityLevel :: Implicit , .. } ) => {
763
+ Some ( ConstStability {
764
+ level : ConstStabilityLevel :: ImplicitUnstable ,
765
+ ..
766
+ } ) => {
765
767
// Intrinsic does not need a separate feature gate (we rely on the
766
768
// regular stability checker). However, we have to worry about recursive
767
769
// const stability.
@@ -815,7 +817,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
815
817
Some ( ConstStability { level : ConstStabilityLevel :: Stable { .. } , .. } ) => {
816
818
// All good.
817
819
}
818
- None | Some ( ConstStability { level : ConstStabilityLevel :: Implicit , .. } ) => {
820
+ None
821
+ | Some ( ConstStability {
822
+ level : ConstStabilityLevel :: ImplicitUnstable , ..
823
+ } ) => {
819
824
// This doesn't need a separate const-stability check -- const-stability equals
820
825
// regular stability, and regular stability is checked separately.
821
826
// However, we *do* have to worry about *recursive* const stability.
@@ -838,43 +843,33 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
838
843
839
844
// We only honor `span.allows_unstable` aka `#[allow_internal_unstable]` if
840
845
// 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
+ {
849
852
return ;
850
853
}
851
854
852
855
// We can't use `check_op` to check whether the feature is enabled because
853
856
// the logic is a bit different than elsewhere: local functions don't need
854
857
// the feature gate, and there might be an "implied" gate that also suffices
855
858
// 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
+ } ) ;
861
864
// We do *not* honor this if we are in the "danger zone": we have to enforce
862
865
// recursive const-stability and the callee is not safe-to-expose. In that
863
866
// case we need `check_op` to do the check.
864
867
let danger_zone = !callee_safe_to_expose_on_stable
865
868
&& 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 {
875
870
self . check_op ( ops:: FnCallUnstable {
876
871
def_id : callee,
877
- features : missing_features ,
872
+ features : unstables . iter ( ) . map ( |u| u . into ( ) ) . collect ( ) ,
878
873
reason : * reason,
879
874
safe_to_expose_on_stable : callee_safe_to_expose_on_stable,
880
875
} ) ;
0 commit comments