@@ -228,7 +228,7 @@ impl<'hir> Map<'hir> {
228
228
let hir_id = self . local_def_id_to_hir_id ( local_def_id) ;
229
229
let def_kind = match self . find ( hir_id) ? {
230
230
Node :: Item ( item) => match item. kind {
231
- ItemKind :: Static ( .. ) => DefKind :: Static ,
231
+ ItemKind :: Static ( _ , mt , _ ) => DefKind :: Static ( mt ) ,
232
232
ItemKind :: Const ( ..) => DefKind :: Const ,
233
233
ItemKind :: Fn ( ..) => DefKind :: Fn ,
234
234
ItemKind :: Macro ( _, macro_kind) => DefKind :: Macro ( macro_kind) ,
@@ -248,7 +248,7 @@ impl<'hir> Map<'hir> {
248
248
} ,
249
249
Node :: ForeignItem ( item) => match item. kind {
250
250
ForeignItemKind :: Fn ( ..) => DefKind :: Fn ,
251
- ForeignItemKind :: Static ( .. ) => DefKind :: Static ,
251
+ ForeignItemKind :: Static ( _ , mt ) => DefKind :: Static ( mt ) ,
252
252
ForeignItemKind :: Type => DefKind :: ForeignTy ,
253
253
} ,
254
254
Node :: TraitItem ( item) => match item. kind {
@@ -471,19 +471,15 @@ impl<'hir> Map<'hir> {
471
471
/// Returns the `BodyOwnerKind` of this `LocalDefId`.
472
472
///
473
473
/// Panics if `LocalDefId` does not have an associated body.
474
- pub fn body_owner_kind ( self , id : HirId ) -> BodyOwnerKind {
475
- match self . get ( id) {
476
- Node :: Item ( & Item { kind : ItemKind :: Const ( ..) , .. } )
477
- | Node :: TraitItem ( & TraitItem { kind : TraitItemKind :: Const ( ..) , .. } )
478
- | Node :: ImplItem ( & ImplItem { kind : ImplItemKind :: Const ( ..) , .. } )
479
- | Node :: AnonConst ( _) => BodyOwnerKind :: Const ,
480
- Node :: Ctor ( ..)
481
- | Node :: Item ( & Item { kind : ItemKind :: Fn ( ..) , .. } )
482
- | Node :: TraitItem ( & TraitItem { kind : TraitItemKind :: Fn ( ..) , .. } )
483
- | Node :: ImplItem ( & ImplItem { kind : ImplItemKind :: Fn ( ..) , .. } ) => BodyOwnerKind :: Fn ,
484
- Node :: Item ( & Item { kind : ItemKind :: Static ( _, m, _) , .. } ) => BodyOwnerKind :: Static ( m) ,
485
- Node :: Expr ( & Expr { kind : ExprKind :: Closure ( ..) , .. } ) => BodyOwnerKind :: Closure ,
486
- node => bug ! ( "{:#?} is not a body node" , node) ,
474
+ pub fn body_owner_kind ( self , def_id : LocalDefId ) -> BodyOwnerKind {
475
+ match self . tcx . def_kind ( def_id) {
476
+ DefKind :: Const | DefKind :: AssocConst | DefKind :: InlineConst | DefKind :: AnonConst => {
477
+ BodyOwnerKind :: Const
478
+ }
479
+ DefKind :: Ctor ( ..) | DefKind :: Fn | DefKind :: AssocFn => BodyOwnerKind :: Fn ,
480
+ DefKind :: Closure | DefKind :: Generator => BodyOwnerKind :: Closure ,
481
+ DefKind :: Static ( mt) => BodyOwnerKind :: Static ( mt) ,
482
+ dk => bug ! ( "{:?} is not a body node: {:?}" , def_id, dk) ,
487
483
}
488
484
}
489
485
@@ -494,16 +490,17 @@ impl<'hir> Map<'hir> {
494
490
/// This should only be used for determining the context of a body, a return
495
491
/// value of `Some` does not always suggest that the owner of the body is `const`,
496
492
/// just that it has to be checked as if it were.
497
- pub fn body_const_context ( self , did : LocalDefId ) -> Option < ConstContext > {
498
- let hir_id = self . local_def_id_to_hir_id ( did) ;
499
- let ccx = match self . body_owner_kind ( hir_id) {
493
+ pub fn body_const_context ( self , def_id : LocalDefId ) -> Option < ConstContext > {
494
+ let ccx = match self . body_owner_kind ( def_id) {
500
495
BodyOwnerKind :: Const => ConstContext :: Const ,
501
496
BodyOwnerKind :: Static ( mt) => ConstContext :: Static ( mt) ,
502
497
503
- BodyOwnerKind :: Fn if self . tcx . is_constructor ( did. to_def_id ( ) ) => return None ,
504
- BodyOwnerKind :: Fn if self . tcx . is_const_fn_raw ( did. to_def_id ( ) ) => ConstContext :: ConstFn ,
498
+ BodyOwnerKind :: Fn if self . tcx . is_constructor ( def_id. to_def_id ( ) ) => return None ,
499
+ BodyOwnerKind :: Fn if self . tcx . is_const_fn_raw ( def_id. to_def_id ( ) ) => {
500
+ ConstContext :: ConstFn
501
+ }
505
502
BodyOwnerKind :: Fn
506
- if self . tcx . has_attr ( did . to_def_id ( ) , sym:: default_method_body_is_const) =>
503
+ if self . tcx . has_attr ( def_id . to_def_id ( ) , sym:: default_method_body_is_const) =>
507
504
{
508
505
ConstContext :: ConstFn
509
506
}
0 commit comments