@@ -4086,28 +4086,55 @@ pub const fn contract_checks() -> bool {
4086
4086
///
4087
4087
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
4088
4088
/// returns false.
4089
+ ///
4090
+ /// Note that this function is a no-op during constant evaluation.
4089
4091
#[ cfg( not( bootstrap) ) ]
4090
- #[ unstable( feature = "contracts_internals" , issue = "128044" /* compiler-team#759 */ ) ]
4092
+ #[ unstable( feature = "contracts_internals" , issue = "128044" ) ]
4093
+ #[ rustc_const_unstable( feature = "contracts" , issue = "128044" ) ]
4091
4094
#[ lang = "contract_check_requires" ]
4092
4095
#[ rustc_intrinsic]
4093
- pub fn contract_check_requires < C : Fn ( ) -> bool > ( cond : C ) {
4094
- if contract_checks ( ) && !cond ( ) {
4095
- // Emit no unwind panic in case this was a safety requirement.
4096
- crate :: panicking:: panic_nounwind ( "failed requires check" ) ;
4097
- }
4096
+ pub const fn contract_check_requires < C : Fn ( ) -> bool + Copy > ( cond : C ) {
4097
+ const_eval_select ! (
4098
+ @capture[ C : Fn ( ) -> bool + Copy ] { cond: C } :
4099
+ if const {
4100
+ // Do nothing
4101
+ } else {
4102
+ if contract_checks( ) && !cond( ) {
4103
+ // Emit no unwind panic in case this was a safety requirement.
4104
+ crate :: panicking:: panic_nounwind( "failed requires check" ) ;
4105
+ }
4106
+ }
4107
+ )
4098
4108
}
4099
4109
4100
4110
/// Check if the post-condition `cond` has been met.
4101
4111
///
4102
4112
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
4103
4113
/// returns false.
4114
+ ///
4115
+ /// Note that this function is a no-op during constant evaluation.
4104
4116
#[ cfg( not( bootstrap) ) ]
4105
- #[ unstable( feature = "contracts_internals" , issue = "128044" /* compiler-team#759 */ ) ]
4106
- #[ rustc_intrinsic]
4107
- pub fn contract_check_ensures < ' a , Ret , C : Fn ( & ' a Ret ) -> bool > ( ret : & ' a Ret , cond : C ) {
4108
- if contract_checks ( ) && !cond ( ret) {
4109
- crate :: panicking:: panic_nounwind ( "failed ensures check" ) ;
4110
- }
4117
+ #[ unstable( feature = "contracts_internals" , issue = "128044" ) ]
4118
+ #[ rustc_const_unstable( feature = "contracts" , issue = "128044" ) ]
4119
+ #[ lang = "contract_check_ensures" ]
4120
+ #[ rustc_intrinsic]
4121
+ pub const fn contract_check_ensures < Ret , C : for < ' a > Fn ( & ' a Ret ) -> bool + Copy > (
4122
+ ret : Ret ,
4123
+ cond : C ,
4124
+ ) -> Ret {
4125
+ const_eval_select ! (
4126
+ @capture[ Ret , C : for <' a> Fn ( & ' a Ret ) -> bool + Copy ] { ret: Ret , cond: C } -> Ret :
4127
+ if const {
4128
+ // Do nothing
4129
+ ret
4130
+ } else {
4131
+ if contract_checks( ) && !cond( & ret) {
4132
+ // Emit no unwind panic in case this was a safety requirement.
4133
+ crate :: panicking:: panic_nounwind( "failed ensures check" ) ;
4134
+ }
4135
+ ret
4136
+ }
4137
+ )
4111
4138
}
4112
4139
4113
4140
/// The intrinsic will return the size stored in that vtable.
0 commit comments