Skip to content

Conversation

dollaransh17
Copy link

This change re-enables the const tests for bool::then_some and bool::then that were previously disabled with a FIXME comment referencing issue 110395.

The tests verify that these methods work correctly in const contexts, which is important for compile-time evaluation. These tests check that both the eager evaluation variant (then_some) and lazy evaluation variant (then) can be used to create constant Option values at compile time.

Tests added:

  • Const evaluation of false.then_some(0) returning None
  • Const evaluation of true.then_some(0) returning Some(0)
  • Const evaluation of false.then(zero) returning None
  • Const evaluation of true.then(zero) returning Some(0)

@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 Oct 3, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 3, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

@rust-log-analyzer

This comment has been minimized.

@dollaransh17 dollaransh17 force-pushed the enable-bool-const-tests branch from 94e8054 to 11a5b42 Compare October 3, 2025 18:01
@rustbot

This comment has been minimized.

@dollaransh17 dollaransh17 force-pushed the enable-bool-const-tests branch from 11a5b42 to 2d11909 Compare October 3, 2025 18:02
@rust-log-analyzer

This comment has been minimized.

This change makes both `then_some` and `then` methods on bool const-compatible,
allowing them to be used in const contexts for compile-time evaluation.

Benefits:
- Enables compile-time conditional Option creation
- Allows usage in const generics and static initialization
- Provides zero-cost abstraction in const contexts
- Improves ergonomics for const programming patterns

The `then_some` method is straightforward to make const as it only uses
basic conditional logic. The `then` method requires a `~const FnOnce`
bound to ensure the closure can be called in const contexts.

This resolves the FIXME in the test suite and enables the const tests
for these methods that were previously disabled.
@dollaransh17 dollaransh17 force-pushed the enable-bool-const-tests branch from 2d11909 to dba9cdf Compare October 3, 2025 18:13
@rust-log-analyzer

This comment has been minimized.

This fixes compilation errors in bootstrap tests by adding:
- rustc_const_stable attribute for then_some method
- rustc_const_unstable attribute for then method
- [const] Destruct bound for const trait compatibility
- Required Destruct import

Resolves E0493 destructor evaluation errors and missing
const stability attribute errors during bootstrap.
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] build_script_build test:false 0.339
error[E0493]: destructor of `T` cannot be evaluated at compile-time
  --> library/core/src/bool.rs:36:37
   |
36 |     pub const fn then_some<T>(self, t: T) -> Option<T> {
   |                                     ^ the destructor for this type cannot be evaluated in constant functions
37 |         if self { Some(t) } else { None }
38 |     }
   |     - value is dropped here

For more information about this error, try `rustc --explain E0493`.
[RUSTC-TIMING] core test:false 24.092

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants