@@ -18,7 +18,7 @@ use rustc_index::vec::Idx;
1818use rustc_span:: def_id:: StableCrateId ;
1919use rustc_span:: hygiene:: MacroKind ;
2020use rustc_span:: source_map:: Spanned ;
21- use rustc_span:: symbol:: { kw, Ident , Symbol } ;
21+ use rustc_span:: symbol:: { kw, sym , Ident , Symbol } ;
2222use rustc_span:: Span ;
2323use rustc_target:: spec:: abi:: Abi ;
2424
@@ -465,6 +465,9 @@ impl<'hir> Map<'hir> {
465465 /// Returns the `ConstContext` of the body associated with this `LocalDefId`.
466466 ///
467467 /// Panics if `LocalDefId` does not have an associated body.
468+ ///
469+ /// This should only be used for determining the context of a body, a return
470+ /// value of `Some` does not always suggest that the owner of the body is `const`.
468471 pub fn body_const_context ( & self , did : LocalDefId ) -> Option < ConstContext > {
469472 let hir_id = self . local_def_id_to_hir_id ( did) ;
470473 let ccx = match self . body_owner_kind ( hir_id) {
@@ -473,6 +476,11 @@ impl<'hir> Map<'hir> {
473476
474477 BodyOwnerKind :: Fn if self . tcx . is_constructor ( did. to_def_id ( ) ) => return None ,
475478 BodyOwnerKind :: Fn if self . tcx . is_const_fn_raw ( did. to_def_id ( ) ) => ConstContext :: ConstFn ,
479+ BodyOwnerKind :: Fn
480+ if self . tcx . has_attr ( did. to_def_id ( ) , sym:: default_method_body_is_const) =>
481+ {
482+ ConstContext :: ConstFn
483+ }
476484 BodyOwnerKind :: Fn | BodyOwnerKind :: Closure => return None ,
477485 } ;
478486
0 commit comments