@@ -937,52 +937,68 @@ extern "rust-intrinsic" {
937
937
#[ rustc_nounwind]
938
938
pub fn unreachable ( ) -> !;
939
939
940
- /// Informs the optimizer that a condition is always true.
941
- /// If the condition is false, the behavior is undefined.
942
- ///
943
- /// No code is generated for this intrinsic, but the optimizer will try
944
- /// to preserve it (and its condition) between passes, which may interfere
945
- /// with optimization of surrounding code and reduce performance. It should
946
- /// not be used if the invariant can be discovered by the optimizer on its
947
- /// own, or if it does not enable any significant optimizations.
948
- ///
949
- /// This intrinsic does not have a stable counterpart.
950
- #[ rustc_const_stable( feature = "const_assume" , since = "1.77.0" ) ]
951
- #[ rustc_nounwind]
952
- pub fn assume ( b : bool ) ;
940
+ }
953
941
954
- /// Hints to the compiler that branch condition is likely to be true.
955
- /// Returns the value passed to it.
956
- ///
957
- /// Any use other than with `if` statements will probably not have an effect.
958
- ///
959
- /// Note that, unlike most intrinsics, this is safe to call;
960
- /// it does not require an `unsafe` block.
961
- /// Therefore, implementations must not require the user to uphold
962
- /// any safety invariants.
963
- ///
964
- /// This intrinsic does not have a stable counterpart.
965
- #[ rustc_const_unstable( feature = "const_likely" , issue = "none" ) ]
966
- #[ rustc_safe_intrinsic]
967
- #[ rustc_nounwind]
968
- pub fn likely ( b : bool ) -> bool ;
942
+ /// Informs the optimizer that a condition is always true.
943
+ /// If the condition is false, the behavior is undefined.
944
+ ///
945
+ /// No code is generated for this intrinsic, but the optimizer will try
946
+ /// to preserve it (and its condition) between passes, which may interfere
947
+ /// with optimization of surrounding code and reduce performance. It should
948
+ /// not be used if the invariant can be discovered by the optimizer on its
949
+ /// own, or if it does not enable any significant optimizations.
950
+ ///
951
+ /// This intrinsic does not have a stable counterpart.
952
+ #[ rustc_const_stable( feature = "const_assume" , since = "1.77.0" ) ]
953
+ #[ rustc_nounwind]
954
+ #[ unstable( feature = "core_intrinsics" , issue = "none" ) ]
955
+ #[ cfg_attr( not( bootstrap) , rustc_intrinsic) ]
956
+ pub const unsafe fn assume ( b : bool ) {
957
+ if !b {
958
+ // SAFETY: the caller must guarantee the argument is never `false`
959
+ unsafe { unreachable ( ) }
960
+ }
961
+ }
969
962
970
- /// Hints to the compiler that branch condition is likely to be false.
971
- /// Returns the value passed to it.
972
- ///
973
- /// Any use other than with `if` statements will probably not have an effect.
974
- ///
975
- /// Note that, unlike most intrinsics, this is safe to call;
976
- /// it does not require an `unsafe` block.
977
- /// Therefore, implementations must not require the user to uphold
978
- /// any safety invariants.
979
- ///
980
- /// This intrinsic does not have a stable counterpart.
981
- #[ rustc_const_unstable( feature = "const_likely" , issue = "none" ) ]
982
- #[ rustc_safe_intrinsic]
983
- #[ rustc_nounwind]
984
- pub fn unlikely ( b : bool ) -> bool ;
963
+ /// Hints to the compiler that branch condition is likely to be true.
964
+ /// Returns the value passed to it.
965
+ ///
966
+ /// Any use other than with `if` statements will probably not have an effect.
967
+ ///
968
+ /// Note that, unlike most intrinsics, this is safe to call;
969
+ /// it does not require an `unsafe` block.
970
+ /// Therefore, implementations must not require the user to uphold
971
+ /// any safety invariants.
972
+ ///
973
+ /// This intrinsic does not have a stable counterpart.
974
+ #[ rustc_const_unstable( feature = "const_likely" , issue = "none" ) ]
975
+ #[ unstable( feature = "core_intrinsics" , issue = "none" ) ]
976
+ #[ cfg_attr( not( bootstrap) , rustc_intrinsic) ]
977
+ #[ rustc_nounwind]
978
+ pub const fn likely ( b : bool ) -> bool {
979
+ b
980
+ }
981
+
982
+ /// Hints to the compiler that branch condition is likely to be false.
983
+ /// Returns the value passed to it.
984
+ ///
985
+ /// Any use other than with `if` statements will probably not have an effect.
986
+ ///
987
+ /// Note that, unlike most intrinsics, this is safe to call;
988
+ /// it does not require an `unsafe` block.
989
+ /// Therefore, implementations must not require the user to uphold
990
+ /// any safety invariants.
991
+ ///
992
+ /// This intrinsic does not have a stable counterpart.
993
+ #[ rustc_const_unstable( feature = "const_likely" , issue = "none" ) ]
994
+ #[ unstable( feature = "core_intrinsics" , issue = "none" ) ]
995
+ #[ cfg_attr( not( bootstrap) , rustc_intrinsic) ]
996
+ #[ rustc_nounwind]
997
+ pub const fn unlikely ( b : bool ) -> bool {
998
+ b
999
+ }
985
1000
1001
+ extern "rust-intrinsic" {
986
1002
/// Executes a breakpoint trap, for inspection by a debugger.
987
1003
///
988
1004
/// This intrinsic does not have a stable counterpart.
0 commit comments