@@ -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
@@ -457,6 +457,9 @@ impl<'hir> Map<'hir> {
457457 /// Returns the `ConstContext` of the body associated with this `LocalDefId`.
458458 ///
459459 /// 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`.
460463 pub fn body_const_context ( & self , did : LocalDefId ) -> Option < ConstContext > {
461464 let hir_id = self . local_def_id_to_hir_id ( did) ;
462465 let ccx = match self . body_owner_kind ( hir_id) {
@@ -465,6 +468,11 @@ impl<'hir> Map<'hir> {
465468
466469 BodyOwnerKind :: Fn if self . tcx . is_constructor ( did. to_def_id ( ) ) => return None ,
467470 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+ }
468476 BodyOwnerKind :: Fn | BodyOwnerKind :: Closure => return None ,
469477 } ;
470478
0 commit comments