@@ -3450,20 +3450,55 @@ pub const fn contract_checks() -> bool {
3450
3450
///
3451
3451
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
3452
3452
/// 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" ) ]
3454
3457
#[ lang = "contract_check_requires" ]
3455
3458
#[ 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
+ )
3461
3471
}
3462
3472
3463
3473
/// Check if the post-condition `cond` has been met.
3464
3474
///
3465
3475
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
3466
3476
/// 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) ]
3467
3502
#[ unstable( feature = "contracts_internals" , issue = "128044" /* compiler-team#759 */ ) ]
3468
3503
#[ rustc_intrinsic]
3469
3504
pub fn contract_check_ensures < ' a , Ret , C : Fn ( & ' a Ret ) -> bool > ( ret : & ' a Ret , cond : C ) {
0 commit comments