Skip to content

Commit 4de53c4

Browse files
authored
Rollup merge of rust-lang#88080 - fee1-dead:iterator-const, r=oli-obk
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. r? `@oli-obk`
2 parents 18a7b6d + 85abdf0 commit 4de53c4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
3+
// This was an ICE, because the compiler ensures the
4+
// function to be const when performing const checking,
5+
// but functions marked with the attribute are not const
6+
// *and* subject to const checking.
7+
8+
#![feature(staged_api)]
9+
#![feature(const_trait_impl)]
10+
#![feature(const_fn_trait_bound)]
11+
#![stable(since = "1", feature = "foo")]
12+
13+
trait Tr {
14+
#[default_method_body_is_const]
15+
fn a() {}
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)