@@ -14,6 +14,7 @@ use std::{fmt, iter, mem};
14
14
15
15
use rustc_abi:: { ExternAbi , FieldIdx , Layout , LayoutData , TargetDataLayout , VariantIdx } ;
16
16
use rustc_ast:: { self as ast, attr} ;
17
+ use rustc_attr:: { ConstStability , StabilityLevel } ;
17
18
use rustc_data_structures:: defer;
18
19
use rustc_data_structures:: fingerprint:: Fingerprint ;
19
20
use rustc_data_structures:: fx:: FxHashMap ;
@@ -3140,6 +3141,35 @@ impl<'tcx> TyCtxt<'tcx> {
3140
3141
&& self . constness ( def_id) == hir:: Constness :: Const
3141
3142
}
3142
3143
3144
+ pub fn enforce_trait_const_stability ( self , trait_def_id : DefId , span : Span ) {
3145
+ match self . lookup_const_stability ( trait_def_id) {
3146
+ Some ( ConstStability {
3147
+ level : StabilityLevel :: Unstable { implied_by : implied_feature, .. } ,
3148
+ feature,
3149
+ ..
3150
+ } ) => {
3151
+ if span. allows_unstable ( feature)
3152
+ || implied_feature. is_some_and ( |f| span. allows_unstable ( f) )
3153
+ {
3154
+ return ;
3155
+ }
3156
+ let feature_enabled = trait_def_id. is_local ( )
3157
+ || self . features ( ) . enabled ( feature)
3158
+ || implied_feature. is_some_and ( |f| self . features ( ) . enabled ( f) ) ;
3159
+
3160
+ if !feature_enabled {
3161
+ let mut diag = self . dcx ( ) . create_err ( crate :: error:: UnstableConstTrait {
3162
+ span,
3163
+ def_path : self . def_path_str ( trait_def_id) ,
3164
+ } ) ;
3165
+ self . disabled_nightly_features ( & mut diag, None , [ ( String :: new ( ) , feature) ] ) ;
3166
+ diag. emit ( ) ;
3167
+ }
3168
+ }
3169
+ _ => { }
3170
+ }
3171
+ }
3172
+
3143
3173
pub fn intrinsic ( self , def_id : impl IntoQueryParam < DefId > + Copy ) -> Option < ty:: IntrinsicDef > {
3144
3174
match self . def_kind ( def_id) {
3145
3175
DefKind :: Fn | DefKind :: AssocFn => { }
0 commit comments