Skip to content

Commit 26b78cc

Browse files
committed
Fix const stability
1 parent 6770dbd commit 26b78cc

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::ops::Deref;
2424
use super::ops::{self, NonConstOp, Status};
2525
use super::qualifs::{self, CustomEq, HasMutInterior, NeedsNonConstDrop};
2626
use super::resolver::FlowSensitiveAnalysis;
27-
use super::{is_lang_special_const_fn, ConstCx, Qualif};
27+
use super::{is_lang_panic_fn, is_lang_special_const_fn, ConstCx, Qualif};
2828
use crate::const_eval::is_unstable_const_fn;
2929

3030
// We are using `MaybeMutBorrowedLocals` as a proxy for whether an item may have been mutated
@@ -910,7 +910,10 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
910910
}
911911
}
912912

913-
return;
913+
if is_lang_panic_fn(tcx, callee) {
914+
// run stability check on non-panic special const fns.
915+
return;
916+
}
914917
}
915918

916919
if Some(callee) == tcx.lang_items().exchange_malloc_fn() {

library/core/src/intrinsics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,7 @@ pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
22582258
issue = "none",
22592259
reason = "const_eval_select will never be stable"
22602260
)]
2261+
#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
22612262
#[lang = "const_eval_select"]
22622263
#[rustc_do_not_const_check]
22632264
pub const unsafe fn const_eval_select<ARG, F, G, RET>(
@@ -2278,6 +2279,7 @@ where
22782279
issue = "none",
22792280
reason = "const_eval_select will never be stable"
22802281
)]
2282+
#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
22812283
#[lang = "const_eval_select_ct"]
22822284
pub const unsafe fn const_eval_select_ct<ARG, F, G, RET>(
22832285
arg: ARG,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(staged_api)]
2+
#![feature(const_eval_select)]
3+
#![stable(since = "1.0", feature = "ui_test")]
4+
5+
use std::intrinsics::const_eval_select;
6+
7+
fn log() {
8+
println!("HEY HEY HEY")
9+
}
10+
11+
const fn nothing(){}
12+
13+
#[stable(since = "1.0", feature = "hey")]
14+
#[rustc_const_stable(since = "1.0", feature = "const_hey")]
15+
pub const unsafe fn hey() {
16+
const_eval_select((), nothing, log);
17+
//~^ ERROR `const_eval_select` is not yet stable as a const fn
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: `const_eval_select` is not yet stable as a const fn
2+
--> $DIR/const-eval-select-stability.rs:16:5
3+
|
4+
LL | const_eval_select((), nothing, log);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: const-stable functions can only call other const-stable functions
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)