提交 fc239e82 编写于 作者: G Gary Guo

Make `likely` and `unlikely` const

They are gated by internal feature gate const_likely
上级 224bc052
......@@ -952,6 +952,7 @@
/// 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.
......@@ -960,6 +961,7 @@
/// 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.
......
......@@ -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)]
......
......@@ -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),
......
......@@ -427,6 +427,7 @@
lhs,
lib,
lifetime,
likely,
line,
link,
linkage,
......@@ -813,6 +814,7 @@
underscore_lifetimes,
uniform_paths,
universal_impl_trait,
unlikely,
unmarked_api,
unreachable_code,
unrestricted_attribute_tokens,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册