@@ -2518,63 +2518,59 @@ extern "rust-intrinsic" {
25182518 G : FnOnce < ARG , Output = RET > ,
25192519 F : FnOnce < ARG , Output = RET > ;
25202520
2521- /// Returns whether the argument's value is statically known at
2522- /// compile-time.
2523- ///
2524- /// This is useful when there is a way of writing the code that will
2525- /// be *faster* when some variables have known values, but *slower*
2526- /// in the general case: an `if is_val_statically_known(var)` can be used
2527- /// to select between these two variants. The `if` will be optimized away
2528- /// and only the desired branch remains.
2529- ///
2530- /// Formally speaking, this function non-deterministically returns `true`
2531- /// or `false`, and the caller has to ensure sound behavior for both cases.
2532- /// In other words, the following code has *Undefined Behavior*:
2533- ///
2534- /// ```no_run
2535- /// #![feature(is_val_statically_known)]
2536- /// #![feature(core_intrinsics)]
2537- /// # #![allow(internal_features)]
2538- /// use std::hint::unreachable_unchecked;
2539- /// use std::intrinsics::is_val_statically_known;
2540- ///
2541- /// unsafe {
2542- /// if !is_val_statically_known(0) { unreachable_unchecked(); }
2543- /// }
2544- /// ```
2545- ///
2546- /// This also means that the following code's behavior is unspecified; it
2547- /// may panic, or it may not:
2548- ///
2549- /// ```no_run
2550- /// #![feature(is_val_statically_known)]
2551- /// #![feature(core_intrinsics)]
2552- /// # #![allow(internal_features)]
2553- /// use std::intrinsics::is_val_statically_known;
2554- ///
2555- /// unsafe {
2556- /// assert_eq!(is_val_statically_known(0), is_val_statically_known(0));
2557- /// }
2558- /// ```
2559- ///
2560- /// Unsafe code may not rely on `is_val_statically_known` returning any
2561- /// particular value, ever. However, the compiler will generally make it
2562- /// return `true` only if the value of the argument is actually known.
2563- ///
2564- /// When calling this in a `const fn`, both paths must be semantically
2565- /// equivalent, that is, the result of the `true` branch and the `false`
2566- /// branch must return the same value and have the same side-effects *no
2567- /// matter what*.
2568- #[ rustc_const_unstable( feature = "is_val_statically_known" , issue = "none" ) ]
2569- #[ rustc_nounwind]
2570- #[ cfg( not( bootstrap) ) ]
2571- pub fn is_val_statically_known < T : Copy > ( arg : T ) -> bool ;
25722521}
25732522
2574- // FIXME: Seems using `unstable` here completely ignores `rustc_allow_const_fn_unstable`
2575- // and thus compiling stage0 core doesn't work.
2523+ /// Returns whether the argument's value is statically known at
2524+ /// compile-time.
2525+ ///
2526+ /// This is useful when there is a way of writing the code that will
2527+ /// be *faster* when some variables have known values, but *slower*
2528+ /// in the general case: an `if is_val_statically_known(var)` can be used
2529+ /// to select between these two variants. The `if` will be optimized away
2530+ /// and only the desired branch remains.
2531+ ///
2532+ /// Formally speaking, this function non-deterministically returns `true`
2533+ /// or `false`, and the caller has to ensure sound behavior for both cases.
2534+ /// In other words, the following code has *Undefined Behavior*:
2535+ ///
2536+ /// ```no_run
2537+ /// #![feature(is_val_statically_known)]
2538+ /// #![feature(core_intrinsics)]
2539+ /// # #![allow(internal_features)]
2540+ /// use std::hint::unreachable_unchecked;
2541+ /// use std::intrinsics::is_val_statically_known;
2542+ ///
2543+ /// unsafe {
2544+ /// if !is_val_statically_known(0) { unreachable_unchecked(); }
2545+ /// }
2546+ /// ```
2547+ ///
2548+ /// This also means that the following code's behavior is unspecified; it
2549+ /// may panic, or it may not:
2550+ ///
2551+ /// ```no_run
2552+ /// #![feature(is_val_statically_known)]
2553+ /// #![feature(core_intrinsics)]
2554+ /// # #![allow(internal_features)]
2555+ /// use std::intrinsics::is_val_statically_known;
2556+ ///
2557+ /// unsafe {
2558+ /// assert_eq!(is_val_statically_known(0), is_val_statically_known(0));
2559+ /// }
2560+ /// ```
2561+ ///
2562+ /// Unsafe code may not rely on `is_val_statically_known` returning any
2563+ /// particular value, ever. However, the compiler will generally make it
2564+ /// return `true` only if the value of the argument is actually known.
2565+ ///
2566+ /// When calling this in a `const fn`, both paths must be semantically
2567+ /// equivalent, that is, the result of the `true` branch and the `false`
2568+ /// branch must return the same value and have the same side-effects *no
2569+ /// matter what*.
2570+ #[ rustc_nounwind]
2571+ #[ unstable( feature = "core_intrinsics" , issue = "none" ) ]
25762572#[ rustc_const_stable( feature = "is_val_statically_known" , since = "0.0.0" ) ]
2577- #[ cfg ( bootstrap) ]
2573+ #[ cfg_attr ( not ( bootstrap) , rustc_intrinsic ( is_val_statically_known ) ) ]
25782574pub const unsafe fn is_val_statically_known < T : Copy > ( _arg : T ) -> bool {
25792575 false
25802576}
0 commit comments