@@ -3120,39 +3120,24 @@ impl<'tcx> TyCtxt<'tcx> {
3120
3120
}
3121
3121
}
3122
3122
3123
- /// Whether the `def_id` counts as const fn in the current crate, considering all active
3124
- /// feature gates
3125
- pub fn is_const_fn ( self , def_id : DefId ) -> bool {
3126
- if self . is_const_fn_raw ( def_id) {
3127
- match self . lookup_const_stability ( def_id) {
3128
- Some ( stability) if stability. is_const_unstable ( ) => {
3129
- // has a `rustc_const_unstable` attribute, check whether the user enabled the
3130
- // corresponding feature gate.
3131
- stability. feature . is_some_and ( |f| self . features ( ) . enabled ( f) )
3132
- }
3133
- // functions without const stability are either stable user written
3134
- // const fn or the user is using feature gates and we thus don't
3135
- // care what they do
3136
- _ => true ,
3123
+ /// Whether `def_id` is a stable const fn (i.e., doesn't need any feature gates to be called).
3124
+ ///
3125
+ /// When this is `false`, the function may still be callable as a `const fn` due to features
3126
+ /// being enabled!
3127
+ pub fn is_stable_const_fn ( self , def_id : DefId ) -> bool {
3128
+ self . is_const_fn ( def_id)
3129
+ && match self . lookup_const_stability ( def_id) {
3130
+ None => true , // a fn in a non-staged_api crate
3131
+ Some ( stability) if stability. is_const_stable ( ) => true ,
3132
+ _ => false ,
3137
3133
}
3138
- } else {
3139
- false
3140
- }
3141
3134
}
3142
3135
3143
3136
// FIXME(effects): Please remove this. It's a footgun.
3144
3137
/// Whether the trait impl is marked const. This does not consider stability or feature gates.
3145
- pub fn is_const_trait_impl_raw ( self , def_id : DefId ) -> bool {
3146
- let Some ( local_def_id) = def_id. as_local ( ) else { return false } ;
3147
- let node = self . hir_node_by_def_id ( local_def_id) ;
3148
-
3149
- matches ! (
3150
- node,
3151
- hir:: Node :: Item ( hir:: Item {
3152
- kind: hir:: ItemKind :: Impl ( hir:: Impl { constness, .. } ) ,
3153
- ..
3154
- } ) if matches!( constness, hir:: Constness :: Const )
3155
- )
3138
+ pub fn is_const_trait_impl ( self , def_id : DefId ) -> bool {
3139
+ self . def_kind ( def_id) == DefKind :: Impl { of_trait : true }
3140
+ && self . constness ( def_id) == hir:: Constness :: Const
3156
3141
}
3157
3142
3158
3143
pub fn intrinsic ( self , def_id : impl IntoQueryParam < DefId > + Copy ) -> Option < ty:: IntrinsicDef > {
0 commit comments