Skip to content

Commit ee85704

Browse files
committed
Skip assert ICE with default_method_body_is_const
functions marked with #[default_method_body_is_const] would ICE when being const checked due to it not being a const function: `tcx.is_const_fn_raw(did)` returns false. We should skip this assert when it is marked with that attribute.
1 parent 58d685e commit ee85704

File tree

1 file changed

+8
-1
lines changed
  • compiler/rustc_mir/src/transform/check_consts

1 file changed

+8
-1
lines changed

compiler/rustc_mir/src/transform/check_consts/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir as hir;
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_middle::mir;
1111
use rustc_middle::ty::{self, TyCtxt};
12-
use rustc_span::Symbol;
12+
use rustc_span::{sym, Symbol};
1313

1414
pub use self::qualifs::Qualif;
1515

@@ -104,6 +104,13 @@ pub fn rustc_allow_const_fn_unstable(
104104
pub fn is_const_stable_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
105105
use attr::{ConstStability, Stability, StabilityLevel};
106106

107+
// A default body marked const is not const-stable because const
108+
// trait fns currently cannot be const-stable. We shouldn't
109+
// restrict default bodies to only call const-stable functions.
110+
if tcx.has_attr(def_id, sym::default_method_body_is_const) {
111+
return false;
112+
}
113+
107114
// Const-stability is only relevant for `const fn`.
108115
assert!(tcx.is_const_fn_raw(def_id));
109116

0 commit comments

Comments
 (0)