about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2021-10-14 06:53:20 +0000
committerDeadbeef <ent3rm4n@gmail.com>2021-10-14 07:07:34 +0000
commit26b78ccd317d7950e0aa9861c7c8e643d92d77cf (patch)
tree0aeb747d656dff753b5e3c7f43c1dd3d98693cc1
parent6770dbd4b5729677bcca6a4c73d3335e523a7ac9 (diff)
downloadrust-26b78ccd317d7950e0aa9861c7c8e643d92d77cf.tar.gz
rust-26b78ccd317d7950e0aa9861c7c8e643d92d77cf.zip
Fix const stability
-rw-r--r--compiler/rustc_const_eval/src/transform/check_consts/check.rs7
-rw-r--r--library/core/src/intrinsics.rs2
-rw-r--r--src/test/ui/intrinsics/const-eval-select-stability.rs20
-rw-r--r--src/test/ui/intrinsics/const-eval-select-stability.stderr10
4 files changed, 37 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs
index 22f14ffbd58..d704c4335c7 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs
@@ -24,7 +24,7 @@ use std::ops::Deref;
 use super::ops::{self, NonConstOp, Status};
 use super::qualifs::{self, CustomEq, HasMutInterior, NeedsNonConstDrop};
 use super::resolver::FlowSensitiveAnalysis;
-use super::{is_lang_special_const_fn, ConstCx, Qualif};
+use super::{is_lang_panic_fn, is_lang_special_const_fn, ConstCx, Qualif};
 use crate::const_eval::is_unstable_const_fn;
 
 // 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> {
                         }
                     }
 
-                    return;
+                    if is_lang_panic_fn(tcx, callee) {
+                        // run stability check on non-panic special const fns.
+                        return;
+                    }
                 }
 
                 if Some(callee) == tcx.lang_items().exchange_malloc_fn() {
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs
index 54d0805550a..886ace193c4 100644
--- a/library/core/src/intrinsics.rs
+++ b/library/core/src/intrinsics.rs
@@ -2258,6 +2258,7 @@ pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
     issue = "none",
     reason = "const_eval_select will never be stable"
 )]
+#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
 #[lang = "const_eval_select"]
 #[rustc_do_not_const_check]
 pub const unsafe fn const_eval_select<ARG, F, G, RET>(
@@ -2278,6 +2279,7 @@ where
     issue = "none",
     reason = "const_eval_select will never be stable"
 )]
+#[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
 #[lang = "const_eval_select_ct"]
 pub const unsafe fn const_eval_select_ct<ARG, F, G, RET>(
     arg: ARG,
diff --git a/src/test/ui/intrinsics/const-eval-select-stability.rs b/src/test/ui/intrinsics/const-eval-select-stability.rs
new file mode 100644
index 00000000000..db2462aee59
--- /dev/null
+++ b/src/test/ui/intrinsics/const-eval-select-stability.rs
@@ -0,0 +1,20 @@
+#![feature(staged_api)]
+#![feature(const_eval_select)]
+#![stable(since = "1.0", feature = "ui_test")]
+
+use std::intrinsics::const_eval_select;
+
+fn log() {
+    println!("HEY HEY HEY")
+}
+
+const fn nothing(){}
+
+#[stable(since = "1.0", feature = "hey")]
+#[rustc_const_stable(since = "1.0", feature = "const_hey")]
+pub const unsafe fn hey() {
+    const_eval_select((), nothing, log);
+    //~^ ERROR `const_eval_select` is not yet stable as a const fn
+}
+
+fn main() {}
diff --git a/src/test/ui/intrinsics/const-eval-select-stability.stderr b/src/test/ui/intrinsics/const-eval-select-stability.stderr
new file mode 100644
index 00000000000..79641bbb46a
--- /dev/null
+++ b/src/test/ui/intrinsics/const-eval-select-stability.stderr
@@ -0,0 +1,10 @@
+error: `const_eval_select` is not yet stable as a const fn
+  --> $DIR/const-eval-select-stability.rs:16:5
+   |
+LL |     const_eval_select((), nothing, log);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: const-stable functions can only call other const-stable functions
+
+error: aborting due to previous error
+