review
This commit is contained in:
parent
d371ebe117
commit
32b13ac928
11 changed files with 73 additions and 59 deletions
|
@ -5,6 +5,7 @@ use crate::dep_graph::{DepGraph, DepKind, DepKindStruct};
|
|||
use crate::hir::place::Place as HirPlace;
|
||||
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
||||
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
|
||||
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
|
||||
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath};
|
||||
use crate::middle::stability;
|
||||
use crate::mir::interpret::{self, Allocation, ConstAllocation, ConstValue, Scalar};
|
||||
|
@ -1066,6 +1067,28 @@ pub struct GlobalCtxt<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Expects a body and returns its codegen attributes.
|
||||
///
|
||||
/// Unlike `codegen_fn_attrs`, this returns `CodegenFnAttrs::EMPTY` for
|
||||
/// constants.
|
||||
pub fn body_codegen_attrs(self, def_id: DefId) -> &'tcx CodegenFnAttrs {
|
||||
let def_kind = self.def_kind(def_id);
|
||||
if def_kind.has_codegen_attrs() {
|
||||
self.codegen_fn_attrs(def_id)
|
||||
} else if matches!(
|
||||
def_kind,
|
||||
DefKind::AnonConst | DefKind::AssocConst | DefKind::Const | DefKind::InlineConst
|
||||
) {
|
||||
CodegenFnAttrs::EMPTY
|
||||
} else {
|
||||
bug!(
|
||||
"body_codegen_fn_attrs called on unexpected definition: {:?} {:?}",
|
||||
def_id,
|
||||
def_kind
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn typeck_opt_const_arg(
|
||||
self,
|
||||
def: ty::WithOptConstParam<LocalDefId>,
|
||||
|
|
|
@ -246,8 +246,7 @@ impl<'tcx> InstanceDef<'tcx> {
|
|||
match *self {
|
||||
InstanceDef::Item(ty::WithOptConstParam { did: def_id, .. })
|
||||
| InstanceDef::Virtual(def_id, _) => {
|
||||
tcx.has_codegen_attrs(tcx.def_kind(def_id))
|
||||
&& tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
|
||||
tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
|
||||
}
|
||||
InstanceDef::ClosureOnceShim { call_once: _, track_caller } => track_caller,
|
||||
_ => false,
|
||||
|
|
|
@ -139,42 +139,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
hasher.finish()
|
||||
}
|
||||
|
||||
pub fn has_codegen_attrs(self, def_kind: DefKind) -> bool {
|
||||
match def_kind {
|
||||
DefKind::Fn
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::Closure
|
||||
| DefKind::Generator
|
||||
| DefKind::Static(_) => true,
|
||||
DefKind::Mod
|
||||
| DefKind::Struct
|
||||
| DefKind::Union
|
||||
| DefKind::Enum
|
||||
| DefKind::Variant
|
||||
| DefKind::Trait
|
||||
| DefKind::TyAlias
|
||||
| DefKind::ForeignTy
|
||||
| DefKind::TraitAlias
|
||||
| DefKind::AssocTy
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Macro(..)
|
||||
| DefKind::Use
|
||||
| DefKind::ForeignMod
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::Impl
|
||||
| DefKind::Field
|
||||
| DefKind::TyParam
|
||||
| DefKind::ConstParam
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::ExternCrate => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn res_generics_def_id(self, res: Res) -> Option<DefId> {
|
||||
match res {
|
||||
Res::Def(DefKind::Ctor(CtorOf::Variant, _), def_id) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue