Skip to content

Conversation

@bend-n
Copy link
Contributor

@bend-n bend-n commented Jan 22, 2026

// 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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 22, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 22, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Copy link
Member

@SpriteOvO SpriteOvO left a 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.

#[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));
*/
}

View changes since this review

@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-all-boolean-methods-under-feature-gate-const-bool branch from fec2775 to 06a0024 Compare January 22, 2026 17:25
@jhpratt
Copy link
Member

jhpratt commented Jan 23, 2026

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

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 23, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 23, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Comment on lines 107 to 123
#[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(()));
}
Copy link
Member

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 😅

@bend-n bend-n mentioned this pull request Jan 23, 2026
3 tasks
@bend-n bend-n force-pushed the constify-all-boolean-methods-under-feature-gate-const-bool branch from 06a0024 to bbef137 Compare January 23, 2026 07:26
@rust-log-analyzer

This comment has been minimized.

@bend-n bend-n force-pushed the constify-all-boolean-methods-under-feature-gate-const-bool branch from bbef137 to 207dcbb Compare January 23, 2026 08:12
@bend-n
Copy link
Contributor Author

bend-n commented Jan 23, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 23, 2026
@jhpratt
Copy link
Member

jhpratt commented Jan 24, 2026

Thanks!

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 24, 2026

📌 Commit 207dcbb has been approved by jhpratt

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 24, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jan 24, 2026
…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
rust-bors bot pushed a commit that referenced this pull request Jan 24, 2026
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
jhpratt added a commit to jhpratt/rust that referenced this pull request Jan 24, 2026
…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
rust-bors bot pushed a commit that referenced this pull request Jan 24, 2026
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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 24, 2026
…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
rust-bors bot pushed a commit that referenced this pull request Jan 24, 2026
…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
@rust-bors rust-bors bot merged commit 474c9fe into rust-lang:main Jan 24, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 24, 2026
rust-timer added a commit that referenced this pull request Jan 24, 2026
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
@bend-n bend-n deleted the constify-all-boolean-methods-under-feature-gate-const-bool branch January 24, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants