pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
/// only checks whether the function has a `const` modifier
fn is_const_fn_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
- let node_id = tcx.hir().as_local_node_id(def_id)
- .expect("Non-local call to local provider is_const_fn");
+ let hir_id = tcx.hir().as_local_hir_id(def_id)
+ .expect("Non-local call to local provider is_const_fn");
- if let Some(fn_like) = FnLikeNode::from_node(tcx.hir().get(node_id)) {
+ if let Some(fn_like) = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)) {
fn_like.constness() == hir::Constness::Const
} else {
false
}
}
+ fn const_fn_is_allowed_fn_ptr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
+ tcx.is_const_fn(def_id) &&
+ tcx.lookup_stability(def_id)
+ .map(|stab| stab.allow_const_fn_ptr).unwrap_or(false)
+ }
+
*providers = Providers {
is_const_fn_raw,
is_promotable_const_fn,
+ const_fn_is_allowed_fn_ptr,
..*providers
};
}