Skip to content

Commit

Permalink
Skip assert ICE with default_method_body_is_const
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fee1-dead committed Aug 16, 2021
1 parent 58d685e commit ee85704
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_mir/src/transform/check_consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::mir;
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::Symbol;
use rustc_span::{sym, Symbol};

pub use self::qualifs::Qualif;

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

// A default body marked const is not const-stable because const
// trait fns currently cannot be const-stable. We shouldn't
// restrict default bodies to only call const-stable functions.
if tcx.has_attr(def_id, sym::default_method_body_is_const) {
return false;
}

// Const-stability is only relevant for `const fn`.
assert!(tcx.is_const_fn_raw(def_id));

Expand Down

0 comments on commit ee85704

Please sign in to comment.