1
Fork 0

Add is_const_impl_raw query

This commit is contained in:
Dylan MacKenzie 2020-02-03 12:21:27 -08:00
parent e0e5d82e16
commit 62ff11f1a4
2 changed files with 23 additions and 1 deletions

View file

@ -279,6 +279,14 @@ rustc_queries! {
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
}
/// Returns `true` if this is a const `impl`. **Do not call this function manually.**
///
/// This query caches the base data for the `is_const_impl` helper function, which also
/// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
query is_const_impl_raw(key: DefId) -> bool {
desc { |tcx| "checking if item is const impl: `{}`", tcx.def_path_str(key) }
}
query asyncness(key: DefId) -> hir::IsAsync {
desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
}

View file

@ -3,7 +3,7 @@ use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
use rustc_attr as attr;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_span::symbol::Symbol;
use rustc_target::spec::abi::Abi;
@ -119,6 +119,19 @@ pub fn provide(providers: &mut Providers<'_>) {
}
}
/// Checks whether the given item is an `impl` that has a `const` modifier.
fn is_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let node = tcx.hir().get(hir_id);
matches!(
node,
hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl { constness: hir::Constness::Const, .. },
..
})
)
}
fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
is_const_fn(tcx, def_id)
&& match tcx.lookup_const_stability(def_id) {
@ -148,6 +161,7 @@ pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers {
is_const_fn_raw,
is_const_impl_raw: |tcx, def_id| is_const_impl_raw(tcx, LocalDefId::from_def_id(def_id)),
is_promotable_const_fn,
const_fn_is_allowed_fn_ptr,
..*providers