]> git.lizzy.rs Git - rust.git/commitdiff
Make `likely` and `unlikely` const
authorGary Guo <gary@garyguo.net>
Fri, 26 Jun 2020 12:19:50 +0000 (13:19 +0100)
committerGary Guo <gary@garyguo.net>
Fri, 26 Jun 2020 20:36:14 +0000 (21:36 +0100)
They are gated by internal feature gate const_likely

src/libcore/intrinsics.rs
src/libcore/lib.rs
src/librustc_mir/interpret/intrinsics.rs
src/librustc_span/symbol.rs

index 2298958b88101c84d39f23aa45e1249214423c8a..da174299fb9af4f8bc4c3778b725c0e259009e2e 100644 (file)
     /// Any use other than with `if` statements will probably not have an effect.
     ///
     /// This intrinsic does not have a stable counterpart.
+    #[rustc_const_unstable(feature = "const_likely", issue = "none")]
     pub fn likely(b: bool) -> bool;
 
     /// Hints to the compiler that branch condition is likely to be false.
     /// Any use other than with `if` statements will probably not have an effect.
     ///
     /// This intrinsic does not have a stable counterpart.
+    #[rustc_const_unstable(feature = "const_likely", issue = "none")]
     pub fn unlikely(b: bool) -> bool;
 
     /// Executes a breakpoint trap, for inspection by a debugger.
index 4eb2fdbd07868a83352e199925cc4780e046d19b..412d323b283a3bd542103d3d56334ddefd51b142 100644 (file)
@@ -92,6 +92,7 @@
 #![feature(const_slice_from_raw_parts)]
 #![feature(const_slice_ptr_len)]
 #![feature(const_type_name)]
+#![feature(const_likely)]
 #![feature(custom_inner_attributes)]
 #![feature(decl_macro)]
 #![feature(doc_cfg)]
index 6ac1e6be03674a9e1cc529ea69548b219c73ba0a..52cb700c3d58f86ddaf15f213e05f5dddb25a5a9 100644 (file)
@@ -399,6 +399,11 @@ pub fn emulate_intrinsic(
                 );
                 self.copy_op(self.operand_index(args[0], index)?, dest)?;
             }
+            sym::likely | sym::unlikely => {
+                // These just return their argument
+                let a = self.read_immediate(args[0])?;
+                self.write_immediate(*a, dest)?;
+            }
             // FIXME(#73156): Handle source code coverage in const eval
             sym::count_code_region => (),
             _ => return Ok(false),
index fa1368b104c7e02e45eb217dfe7f9024693babd6..3e62486feb95ef02b62aabc2b0f1c4612b1ebb09 100644 (file)
         lhs,
         lib,
         lifetime,
+        likely,
         line,
         link,
         linkage,
         underscore_lifetimes,
         uniform_paths,
         universal_impl_trait,
+        unlikely,
         unmarked_api,
         unreachable_code,
         unrestricted_attribute_tokens,