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