@@ -4,14 +4,18 @@ use rustc_hir::def_id::{DefId, LocalDefId};
4
4
use rustc_middle:: query:: Providers ;
5
5
use rustc_middle:: ty:: TyCtxt ;
6
6
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 {
8
8
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 ,
15
19
}
16
20
}
17
21
@@ -34,7 +38,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
34
38
35
39
// If the function itself is not annotated with `const`, it may still be a `const fn`
36
40
// if it resides in a const trait impl.
37
- parent_impl_constness ( tcx, def_id)
41
+ parent_impl_or_trait_constness ( tcx, def_id)
38
42
} else {
39
43
tcx. dcx ( ) . span_bug (
40
44
tcx. def_span ( def_id) ,
0 commit comments