@@ -99,8 +99,16 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
99
99
100
100
let node = tcx. hir ( ) . get ( hir_id) ;
101
101
102
- if let Some ( whitelisted) = is_const_intrinsic ( tcx, def_id) {
103
- whitelisted
102
+ if let hir:: Node :: ForeignItem ( hir:: ForeignItem { kind : hir:: ForeignItemKind :: Fn ( ..) , .. } ) =
103
+ node
104
+ {
105
+ // Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
106
+ // foreign items cannot be evaluated at compile-time.
107
+ if let Abi :: RustIntrinsic | Abi :: PlatformIntrinsic = tcx. hir ( ) . get_foreign_abi ( hir_id) {
108
+ tcx. lookup_const_stability ( def_id) . is_some ( )
109
+ } else {
110
+ false
111
+ }
104
112
} else if let Some ( fn_like) = FnLikeNode :: from_node ( node) {
105
113
if fn_like. constness ( ) == hir:: Constness :: Const {
106
114
return true ;
@@ -116,21 +124,6 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
116
124
}
117
125
}
118
126
119
- /// Const evaluability whitelist is here to check evaluability at the
120
- /// top level beforehand.
121
- fn is_const_intrinsic ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Option < bool > {
122
- if tcx. is_closure ( def_id) {
123
- return None ;
124
- }
125
-
126
- match tcx. fn_sig ( def_id) . abi ( ) {
127
- Abi :: RustIntrinsic | Abi :: PlatformIntrinsic => {
128
- Some ( tcx. lookup_const_stability ( def_id) . is_some ( ) )
129
- }
130
- _ => None ,
131
- }
132
- }
133
-
134
127
/// Checks whether the given item is an `impl` that has a `const` modifier.
135
128
fn is_const_impl_raw ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
136
129
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
0 commit comments