@@ -3288,20 +3288,55 @@ pub const fn contract_checks() -> bool {
3288
3288
///
3289
3289
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
3290
3290
/// returns false.
3291
- #[ unstable( feature = "contracts_internals" , issue = "128044" /* compiler-team#759 */ ) ]
3291
+ ///
3292
+ /// Note that this function is a no-op during constant evaluation.
3293
+ #[ unstable( feature = "contracts_internals" , issue = "128044" ) ]
3294
+ #[ rustc_const_unstable( feature = "contracts" , issue = "128044" ) ]
3292
3295
#[ lang = "contract_check_requires" ]
3293
3296
#[ rustc_intrinsic]
3294
- pub fn contract_check_requires < C : Fn ( ) -> bool > ( cond : C ) {
3295
- if contract_checks ( ) && !cond ( ) {
3296
- // Emit no unwind panic in case this was a safety requirement.
3297
- crate :: panicking:: panic_nounwind ( "failed requires check" ) ;
3298
- }
3297
+ pub const fn contract_check_requires < C : Fn ( ) -> bool + Copy > ( cond : C ) {
3298
+ const_eval_select ! (
3299
+ @capture[ C : Fn ( ) -> bool + Copy ] { cond: C } :
3300
+ if const {
3301
+ // Do nothing
3302
+ } else {
3303
+ if contract_checks( ) && !cond( ) {
3304
+ // Emit no unwind panic in case this was a safety requirement.
3305
+ crate :: panicking:: panic_nounwind( "failed requires check" ) ;
3306
+ }
3307
+ }
3308
+ )
3299
3309
}
3300
3310
3301
3311
/// Check if the post-condition `cond` has been met.
3302
3312
///
3303
3313
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
3304
3314
/// returns false.
3315
+ ///
3316
+ /// Note that this function is a no-op during constant evaluation.
3317
+ #[ cfg( not( bootstrap) ) ]
3318
+ #[ unstable( feature = "contracts_internals" , issue = "128044" ) ]
3319
+ #[ rustc_const_unstable( feature = "contracts" , issue = "128044" ) ]
3320
+ #[ lang = "contract_check_ensures" ]
3321
+ #[ rustc_intrinsic]
3322
+ pub const fn contract_check_ensures < Ret , C : Fn ( & Ret ) -> bool + Copy > ( ret : Ret , cond : C ) -> Ret {
3323
+ const_eval_select ! (
3324
+ @capture[ Ret , C : Fn ( & Ret ) -> bool + Copy ] { ret: Ret , cond: C } -> Ret :
3325
+ if const {
3326
+ // Do nothing
3327
+ ret
3328
+ } else {
3329
+ if contract_checks( ) && !cond( & ret) {
3330
+ // Emit no unwind panic in case this was a safety requirement.
3331
+ crate :: panicking:: panic_nounwind( "failed ensures check" ) ;
3332
+ }
3333
+ ret
3334
+ }
3335
+ )
3336
+ }
3337
+
3338
+ /// This is the old version of contract_check_ensures kept here for bootstrap only.
3339
+ #[ cfg( bootstrap) ]
3305
3340
#[ unstable( feature = "contracts_internals" , issue = "128044" /* compiler-team#759 */ ) ]
3306
3341
#[ rustc_intrinsic]
3307
3342
pub fn contract_check_ensures < ' a , Ret , C : Fn ( & ' a Ret ) -> bool > ( ret : & ' a Ret , cond : C ) {
0 commit comments