@@ -18,7 +18,7 @@ use rustc_index::vec::Idx;
18
18
use rustc_span:: def_id:: StableCrateId ;
19
19
use rustc_span:: hygiene:: MacroKind ;
20
20
use rustc_span:: source_map:: Spanned ;
21
- use rustc_span:: symbol:: { kw, Ident , Symbol } ;
21
+ use rustc_span:: symbol:: { kw, sym , Ident , Symbol } ;
22
22
use rustc_span:: Span ;
23
23
use rustc_target:: spec:: abi:: Abi ;
24
24
@@ -457,6 +457,9 @@ impl<'hir> Map<'hir> {
457
457
/// Returns the `ConstContext` of the body associated with this `LocalDefId`.
458
458
///
459
459
/// Panics if `LocalDefId` does not have an associated body.
460
+ ///
461
+ /// This should only be used for determining the context of a body, a return
462
+ /// value of `Some` does not always suggest that the owner of the body is `const`.
460
463
pub fn body_const_context ( & self , did : LocalDefId ) -> Option < ConstContext > {
461
464
let hir_id = self . local_def_id_to_hir_id ( did) ;
462
465
let ccx = match self . body_owner_kind ( hir_id) {
@@ -465,6 +468,11 @@ impl<'hir> Map<'hir> {
465
468
466
469
BodyOwnerKind :: Fn if self . tcx . is_constructor ( did. to_def_id ( ) ) => return None ,
467
470
BodyOwnerKind :: Fn if self . tcx . is_const_fn_raw ( did. to_def_id ( ) ) => ConstContext :: ConstFn ,
471
+ BodyOwnerKind :: Fn
472
+ if self . tcx . has_attr ( did. to_def_id ( ) , sym:: default_method_body_is_const) =>
473
+ {
474
+ ConstContext :: ConstFn
475
+ }
468
476
BodyOwnerKind :: Fn | BodyOwnerKind :: Closure => return None ,
469
477
} ;
470
478
0 commit comments