-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
constify boolean methods #151489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
constify boolean methods #151489
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I prefer the name const_bool_ops for this feature gate.
It would be nice if you could also remove the FIXME and enable these tests for const.
rust/library/coretests/tests/bool.rs
Lines 85 to 107 in d29e478
| #[test] | |
| fn test_bool_to_option() { | |
| assert_eq!(false.then_some(0), None); | |
| assert_eq!(true.then_some(0), Some(0)); | |
| assert_eq!(false.then(|| 0), None); | |
| assert_eq!(true.then(|| 0), Some(0)); | |
| /* FIXME(#110395) | |
| const fn zero() -> i32 { | |
| 0 | |
| } | |
| const A: Option<i32> = false.then_some(0); | |
| const B: Option<i32> = true.then_some(0); | |
| const C: Option<i32> = false.then(zero); | |
| const D: Option<i32> = true.then(zero); | |
| assert_eq!(A, None); | |
| assert_eq!(B, Some(0)); | |
| assert_eq!(C, None); | |
| assert_eq!(D, Some(0)); | |
| */ | |
| } |
This comment has been minimized.
This comment has been minimized.
fec2775 to
06a0024
Compare
|
My understanding is we're in the "constify everything" phase, so feel free to create a tracking issue. Let me know when that's done (and the PR updated with the issue number) and I'll approve it. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
| #[test] | ||
| fn test_bool_to_result() { | ||
| assert_eq!(false.ok_or(0), Err(0)); | ||
| assert_eq!(true.ok_or(0), Ok(())); | ||
| assert_eq!(false.ok_or_else(|| 0), Err(0)); | ||
| assert_eq!(true.ok_or_else(|| 0), Ok(())); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add some const test cases for ok_or ok_or_else here? Like the ones above. I forgot to say it yesterday, sorry 😅
06a0024 to
bbef137
Compare
This comment has been minimized.
This comment has been minimized.
bbef137 to
207dcbb
Compare
|
@rustbot ready |
|
Thanks! @bors r+ rollup |
…s-under-feature-gate-const-bool, r=jhpratt
constify boolean methods
```rs
// core::bool
impl bool {
pub const fn then_some<T: [const] Destruct>(self, t: T) -> Option<T>;
pub const fn then<T, F: [const] FnOnce() -> T + [const] Destruct>(self, f: F) -> Option<T>;
pub const fn ok_or<E: [const] Destruct>(self, err: E) -> Result<(), E>;
pub const fn ok_or_else<E, F: [const] FnOnce() -> E + [const] Destruct>;
}
```
will make tracking issue if pr liked
Rollup of 8 pull requests Successful merges: - #150556 (Add Tier 3 Thumb-mode targets for Armv7-A, Armv7-R and Armv8-R) - #151346 (add `simd_splat` intrinsic) - #151500 (hexagon: Add HVX target features) - #151505 (Various refactors to the proc_macro bridge) - #151517 (Enable reproducible binary builds with debuginfo on Linux) - #151482 (Add "Skip to main content" link for keyboard navigation in rustdoc) - #151489 (constify boolean methods) - #151551 (Don't use default build-script fingerprinting in `test`) r? @ghost
…s-under-feature-gate-const-bool, r=jhpratt
constify boolean methods
```rs
// core::bool
impl bool {
pub const fn then_some<T: [const] Destruct>(self, t: T) -> Option<T>;
pub const fn then<T, F: [const] FnOnce() -> T + [const] Destruct>(self, f: F) -> Option<T>;
pub const fn ok_or<E: [const] Destruct>(self, err: E) -> Result<(), E>;
pub const fn ok_or_else<E, F: [const] FnOnce() -> E + [const] Destruct>;
}
```
will make tracking issue if pr liked
Rollup of 8 pull requests Successful merges: - #150556 (Add Tier 3 Thumb-mode targets for Armv7-A, Armv7-R and Armv8-R) - #151500 (hexagon: Add HVX target features) - #151505 (Various refactors to the proc_macro bridge) - #151517 (Enable reproducible binary builds with debuginfo on Linux) - #151482 (Add "Skip to main content" link for keyboard navigation in rustdoc) - #151489 (constify boolean methods) - #151551 (Don't use default build-script fingerprinting in `test`) - #151555 (Fix compilation of std/src/sys/pal/uefi/tests.rs) r? @ghost
…s-under-feature-gate-const-bool, r=jhpratt
constify boolean methods
```rs
// core::bool
impl bool {
pub const fn then_some<T: [const] Destruct>(self, t: T) -> Option<T>;
pub const fn then<T, F: [const] FnOnce() -> T + [const] Destruct>(self, f: F) -> Option<T>;
pub const fn ok_or<E: [const] Destruct>(self, err: E) -> Result<(), E>;
pub const fn ok_or_else<E, F: [const] FnOnce() -> E + [const] Destruct>;
}
```
will make tracking issue if pr liked
…uwer Rollup of 8 pull requests Successful merges: - #150556 (Add Tier 3 Thumb-mode targets for Armv7-A, Armv7-R and Armv8-R) - #151259 (Fix is_ascii performance regression on AVX-512 CPUs when compiling with -C target-cpu=native) - #151500 (hexagon: Add HVX target features) - #151517 (Enable reproducible binary builds with debuginfo on Linux) - #151482 (Add "Skip to main content" link for keyboard navigation in rustdoc) - #151489 (constify boolean methods) - #151551 (Don't use default build-script fingerprinting in `test`) - #151555 (Fix compilation of std/src/sys/pal/uefi/tests.rs) r? @ghost
Rollup merge of #151489 - bend-n:constify-all-boolean-methods-under-feature-gate-const-bool, r=jhpratt constify boolean methods ```rs // core::bool impl bool { pub const fn then_some<T: [const] Destruct>(self, t: T) -> Option<T>; pub const fn then<T, F: [const] FnOnce() -> T + [const] Destruct>(self, f: F) -> Option<T>; pub const fn ok_or<E: [const] Destruct>(self, err: E) -> Result<(), E>; pub const fn ok_or_else<E, F: [const] FnOnce() -> E + [const] Destruct>; } ``` will make tracking issue if pr liked
will make tracking issue if pr liked