@@ -5,6 +5,7 @@ use crate::dep_graph::{DepGraph, DepKind, DepKindStruct};
5
5
use crate :: hir:: place:: Place as HirPlace ;
6
6
use crate :: infer:: canonical:: { Canonical , CanonicalVarInfo , CanonicalVarInfos } ;
7
7
use crate :: lint:: { struct_lint_level, LintDiagnosticBuilder , LintLevelSource } ;
8
+ use crate :: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
8
9
use crate :: middle:: resolve_lifetime:: { self , LifetimeScopeForPath } ;
9
10
use crate :: middle:: stability;
10
11
use crate :: mir:: interpret:: { self , Allocation , ConstAllocation , ConstValue , Scalar } ;
@@ -1066,6 +1067,28 @@ pub struct GlobalCtxt<'tcx> {
1066
1067
}
1067
1068
1068
1069
impl < ' tcx > TyCtxt < ' tcx > {
1070
+ /// Expects a body and returns its codegen attributes.
1071
+ ///
1072
+ /// Unlike `codegen_fn_attrs`, this returns `CodegenFnAttrs::EMPTY` for
1073
+ /// constants.
1074
+ pub fn body_codegen_attrs ( self , def_id : DefId ) -> & ' tcx CodegenFnAttrs {
1075
+ let def_kind = self . def_kind ( def_id) ;
1076
+ if def_kind. has_codegen_attrs ( ) {
1077
+ self . codegen_fn_attrs ( def_id)
1078
+ } else if matches ! (
1079
+ def_kind,
1080
+ DefKind :: AnonConst | DefKind :: AssocConst | DefKind :: Const | DefKind :: InlineConst
1081
+ ) {
1082
+ CodegenFnAttrs :: EMPTY
1083
+ } else {
1084
+ bug ! (
1085
+ "body_codegen_fn_attrs called on unexpected definition: {:?} {:?}" ,
1086
+ def_id,
1087
+ def_kind
1088
+ )
1089
+ }
1090
+ }
1091
+
1069
1092
pub fn typeck_opt_const_arg (
1070
1093
self ,
1071
1094
def : ty:: WithOptConstParam < LocalDefId > ,
0 commit comments