@@ -4,14 +4,18 @@ use rustc_hir::def_id::{DefId, LocalDefId};
44use rustc_middle:: query:: Providers ;
55use rustc_middle:: ty:: TyCtxt ;
66
7- fn parent_impl_constness ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> hir:: Constness {
7+ fn parent_impl_or_trait_constness ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> hir:: Constness {
88 let parent_id = tcx. local_parent ( def_id) ;
9- if matches ! ( tcx. def_kind( parent_id) , DefKind :: Impl { .. } )
10- && let Some ( header) = tcx. impl_trait_header ( parent_id)
11- {
12- header. constness
13- } else {
14- hir:: Constness :: NotConst
9+ match tcx. def_kind ( parent_id) {
10+ DefKind :: Impl { of_trait : true } => tcx. impl_trait_header ( parent_id) . unwrap ( ) . constness ,
11+ DefKind :: Trait => {
12+ if tcx. is_const_trait ( parent_id. into ( ) ) {
13+ hir:: Constness :: Const
14+ } else {
15+ hir:: Constness :: NotConst
16+ }
17+ }
18+ _ => hir:: Constness :: NotConst ,
1519 }
1620}
1721
@@ -34,7 +38,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
3438
3539 // If the function itself is not annotated with `const`, it may still be a `const fn`
3640 // if it resides in a const trait impl.
37- parent_impl_constness ( tcx, def_id)
41+ parent_impl_or_trait_constness ( tcx, def_id)
3842 } else {
3943 tcx. dcx ( ) . span_bug (
4044 tcx. def_span ( def_id) ,
0 commit comments