functions marked with attr are not const
This commit is contained in:
parent
89d190f090
commit
27e863b3df
2 changed files with 9 additions and 4 deletions
|
@ -18,7 +18,7 @@ use rustc_index::vec::Idx;
|
||||||
use rustc_span::def_id::StableCrateId;
|
use rustc_span::def_id::StableCrateId;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
|
|
||||||
|
@ -457,6 +457,9 @@ impl<'hir> Map<'hir> {
|
||||||
/// Returns the `ConstContext` of the body associated with this `LocalDefId`.
|
/// Returns the `ConstContext` of the body associated with this `LocalDefId`.
|
||||||
///
|
///
|
||||||
/// Panics if `LocalDefId` does not have an associated body.
|
/// Panics if `LocalDefId` does not have an associated body.
|
||||||
|
///
|
||||||
|
/// This should only be used for determining the context of a body, a return
|
||||||
|
/// value of `Some` does not always suggest that the owner of the body is `const`.
|
||||||
pub fn body_const_context(&self, did: LocalDefId) -> Option<ConstContext> {
|
pub fn body_const_context(&self, did: LocalDefId) -> Option<ConstContext> {
|
||||||
let hir_id = self.local_def_id_to_hir_id(did);
|
let hir_id = self.local_def_id_to_hir_id(did);
|
||||||
let ccx = match self.body_owner_kind(hir_id) {
|
let ccx = match self.body_owner_kind(hir_id) {
|
||||||
|
@ -465,6 +468,11 @@ impl<'hir> Map<'hir> {
|
||||||
|
|
||||||
BodyOwnerKind::Fn if self.tcx.is_constructor(did.to_def_id()) => return None,
|
BodyOwnerKind::Fn if self.tcx.is_constructor(did.to_def_id()) => return None,
|
||||||
BodyOwnerKind::Fn if self.tcx.is_const_fn_raw(did.to_def_id()) => ConstContext::ConstFn,
|
BodyOwnerKind::Fn if self.tcx.is_const_fn_raw(did.to_def_id()) => ConstContext::ConstFn,
|
||||||
|
BodyOwnerKind::Fn
|
||||||
|
if self.tcx.has_attr(did.to_def_id(), sym::default_method_body_is_const) =>
|
||||||
|
{
|
||||||
|
ConstContext::ConstFn
|
||||||
|
}
|
||||||
BodyOwnerKind::Fn | BodyOwnerKind::Closure => return None,
|
BodyOwnerKind::Fn | BodyOwnerKind::Closure => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,6 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if tcx.has_attr(def_id, sym::default_method_body_is_const) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// If the function itself is not annotated with `const`, it may still be a `const fn`
|
// If the function itself is not annotated with `const`, it may still be a `const fn`
|
||||||
// if it resides in a const trait impl.
|
// if it resides in a const trait impl.
|
||||||
is_parent_const_impl_raw(tcx, hir_id)
|
is_parent_const_impl_raw(tcx, hir_id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue