]> git.lizzy.rs Git - rust.git/commitdiff
Fix const stability
authorDeadbeef <ent3rm4n@gmail.com>
Thu, 14 Oct 2021 06:53:20 +0000 (06:53 +0000)
committerDeadbeef <ent3rm4n@gmail.com>
Thu, 14 Oct 2021 07:07:34 +0000 (07:07 +0000)
compiler/rustc_const_eval/src/transform/check_consts/check.rs
library/core/src/intrinsics.rs
src/test/ui/intrinsics/const-eval-select-stability.rs [new file with mode: 0644]
src/test/ui/intrinsics/const-eval-select-stability.stderr [new file with mode: 0644]

index 22f14ffbd583a26661fec76158bb25b5756357f6..d704c4335c7540503b371e146fb38f31aaf7465a 100644 (file)
@@ -24,7 +24,7 @@
 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 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
                         }
                     }
 
-                    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() {
index 54d0805550ac560e065cb4e43d6cbf5a42a43848..886ace193c428dad394ac877eb45dbc3ddf77bf5 100644 (file)
@@ -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 @@ 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_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 (file)
index 0000000..db2462a
--- /dev/null
@@ -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 (file)
index 0000000..79641bb
--- /dev/null
@@ -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
+