File tree 2 files changed +11
-10
lines changed
compiler/rustc_const_eval/src/const_eval
2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,16 @@ use rustc_middle::ty::TyCtxt;
6
6
7
7
fn parent_impl_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
Original file line number Diff line number Diff line change @@ -360,10 +360,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
360
360
// sensitive check here. But we can at least rule out functions that are not const at
361
361
// all. That said, we have to allow calling functions inside a trait marked with
362
362
// #[const_trait]. These *are* const-checked!
363
- // FIXME(const_trait_impl): why does `is_const_fn` not classify them as const?
364
- if ( !ecx. tcx . is_const_fn ( def) && !ecx. tcx . is_const_default_method ( def) )
365
- || ecx. tcx . has_attr ( def, sym:: rustc_do_not_const_check)
366
- {
363
+ if !ecx. tcx . is_const_fn ( def) || ecx. tcx . has_attr ( def, sym:: rustc_do_not_const_check) {
367
364
// We certainly do *not* want to actually call the fn
368
365
// though, so be sure we return here.
369
366
throw_unsup_format ! ( "calling non-const function `{}`" , instance)
You can’t perform that action at this time.
0 commit comments