@@ -3450,20 +3450,55 @@ pub const fn contract_checks() -> bool {
34503450///
34513451/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
34523452/// returns false.
3453- #[ unstable( feature = "contracts_internals" , issue = "128044" /* compiler-team#759 */ ) ]
3453+ ///
3454+ /// Note that this function is a no-op during constant evaluation.
3455+ #[ unstable( feature = "contracts_internals" , issue = "128044" ) ]
3456+ #[ rustc_const_unstable( feature = "contracts" , issue = "128044" ) ]
34543457#[ lang = "contract_check_requires" ]
34553458#[ rustc_intrinsic]
3456- pub fn contract_check_requires < C : Fn ( ) -> bool > ( cond : C ) {
3457- if contract_checks ( ) && !cond ( ) {
3458- // Emit no unwind panic in case this was a safety requirement.
3459- crate :: panicking:: panic_nounwind ( "failed requires check" ) ;
3460- }
3459+ pub const fn contract_check_requires < C : Fn ( ) -> bool + Copy > ( cond : C ) {
3460+ const_eval_select ! (
3461+ @capture[ C : Fn ( ) -> bool + Copy ] { cond: C } :
3462+ if const {
3463+ // Do nothing
3464+ } else {
3465+ if contract_checks( ) && !cond( ) {
3466+ // Emit no unwind panic in case this was a safety requirement.
3467+ crate :: panicking:: panic_nounwind( "failed requires check" ) ;
3468+ }
3469+ }
3470+ )
34613471}
34623472
34633473/// Check if the post-condition `cond` has been met.
34643474///
34653475/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
34663476/// returns false.
3477+ ///
3478+ /// Note that this function is a no-op during constant evaluation.
3479+ #[ cfg( not( bootstrap) ) ]
3480+ #[ unstable( feature = "contracts_internals" , issue = "128044" ) ]
3481+ #[ rustc_const_unstable( feature = "contracts" , issue = "128044" ) ]
3482+ #[ lang = "contract_check_ensures" ]
3483+ #[ rustc_intrinsic]
3484+ pub const fn contract_check_ensures < Ret , C : Fn ( & Ret ) -> bool + Copy > ( ret : Ret , cond : C ) -> Ret {
3485+ const_eval_select ! (
3486+ @capture[ Ret , C : Fn ( & Ret ) -> bool + Copy ] { ret: Ret , cond: C } -> Ret :
3487+ if const {
3488+ // Do nothing
3489+ ret
3490+ } else {
3491+ if contract_checks( ) && !cond( & ret) {
3492+ // Emit no unwind panic in case this was a safety requirement.
3493+ crate :: panicking:: panic_nounwind( "failed ensures check" ) ;
3494+ }
3495+ ret
3496+ }
3497+ )
3498+ }
3499+
3500+ /// This is the old version of contract_check_ensures kept here for bootstrap only.
3501+ #[ cfg( bootstrap) ]
34673502#[ unstable( feature = "contracts_internals" , issue = "128044" /* compiler-team#759 */ ) ]
34683503#[ rustc_intrinsic]
34693504pub fn contract_check_ensures < ' a , Ret , C : Fn ( & ' a Ret ) -> bool > ( ret : & ' a Ret , cond : C ) {
0 commit comments