Skip to content

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 15, 2025

r? @fee1-dead

tracking issue: #143956

these unblock making PartialOrd and Ord const without resorting to inlining some of these at call sites.

@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 Jul 15, 2025
T: ~const Destruct,
{
match self {
x @ Some(_) => x,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern was introduced in #116481 because it optimizes better.

Comment on lines +1640 to +1642
//FIXME(const_hack): this `T: ~const Destruct` is unnecessary, but even precise live drops can't tell
// no value of type `T` gets dropped here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling this will nerdsnipe me hard.

Here's how code is currently generated

#![feature(const_destruct)] #![feature(const_trait_impl)] use std::marker::Destruct; pub const fn opt_or_else<T, F>(this: Option<T>, f: F) -> Option<T> where F: ~const Destruct + ~const FnOnce() -> Option<T>, T: ~const Destruct { match this { x @ Some(_) => x, None => f() } }
// MIR FOR CTFE fn opt_or_else(_1: Option<T>, _2: F) -> Option<T> { debug this => _1; debug f => _2; let mut _0: std::option::Option<T>; let mut _3: isize; let _4: std::option::Option<T>; let mut _5: F; let mut _6: (); let mut _7: bool; let mut _8: bool; scope 1 { debug x => _4; } bb0: { _8 = const false; _7 = const false; _8 = const true; _7 = const true; _3 = discriminant(_1); switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb1]; } bb1: { unreachable; } bb2: { StorageLive(_5); _7 = const false; _5 = move _2; StorageLive(_6); _6 = (); ConstEvalCounter; _0 = <F as FnOnce<()>>::call_once(move _5, move _6) -> [return: bb4, unwind: bb12]; } bb3: { StorageLive(_4); _8 = const false; _4 = move _1; _0 = move _4; StorageDead(_4); goto -> bb9; } bb4: { StorageDead(_6); StorageDead(_5); goto -> bb9; } bb5: { switchInt(copy _8) -> [0: bb6, otherwise: bb10]; } bb6: { return; } bb7 (cleanup): { resume; } bb8: { drop(_2) -> [return: bb5, unwind: bb12]; } bb9: { switchInt(copy _7) -> [0: bb5, otherwise: bb8]; } bb10: { drop(_1) -> [return: bb6, unwind: bb7]; } bb11 (cleanup): { drop(_1) -> [return: bb7, unwind terminate(cleanup)]; } bb12 (cleanup): { switchInt(copy _8) -> [0: bb7, otherwise: bb11]; } }

looks like it tries to drop self at the None arm, which is just weird.

Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me after nit

#[stable(feature = "is_some_and", since = "1.70.0")]
pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool {
#[rustc_const_unstable(feature = "const_option_ops", issue = "143956")]
pub const fn is_some_and(self, f: impl ~const Destruct + ~const FnOnce(T) -> bool) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should put FnOnce first, here and elsewhere in the PR. the destruct bound is noisy and likely to make it harder for someone to read the code.

@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 Jul 17, 2025
@oli-obk oli-obk force-pushed the const-option-methods branch from 5d2acad to 853333d Compare July 17, 2025 09:11
@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 17, 2025

@bors r=fee1-dead

@bors
Copy link
Collaborator

bors commented Jul 17, 2025

📌 Commit 853333d has been approved by fee1-dead

It is now in the queue for this repository.

@bors bors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 17, 2025
fmease added a commit to fmease/rust that referenced this pull request Jul 17, 2025
…e1-dead constify `Option` methods r? `@fee1-dead` tracking issue: rust-lang#143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
fmease added a commit to fmease/rust that referenced this pull request Jul 17, 2025
…e1-dead constify `Option` methods r? ``@fee1-dead`` tracking issue: rust-lang#143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 15 pull requests Successful merges: - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - #143271 (Store the type of each GVN value) - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - #143719 (Emit warning when there is no space between `-o` and arg) - #143833 (Ban projecting into SIMD types [MCP838]) - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - #143879 (parse `const trait Trait`) - #143891 (Port `#[coverage]` to the new attribute system) - #143967 (constify `Option` methods) - #143985 (rustc_public: de-StableMIR-ize) - #144008 (Fix false positive double negations with macro invocation) - #144010 (Boostrap: add warning on `optimize = false`) - #144034 (tests: Test line number in debuginfo for diverging function calls) - #144049 (rustc-dev-guide subtree update) - #144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 17, 2025
…e1-dead constify `Option` methods r? ```@fee1-dead``` tracking issue: rust-lang#143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 12 pull requests Successful merges: - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - #143271 (Store the type of each GVN value) - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - #143719 (Emit warning when there is no space between `-o` and arg) - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - #143891 (Port `#[coverage]` to the new attribute system) - #143967 (constify `Option` methods) - #144008 (Fix false positive double negations with macro invocation) - #144010 (Boostrap: add warning on `optimize = false`) - #144034 (tests: Test line number in debuginfo for diverging function calls) - #144049 (rustc-dev-guide subtree update) - #144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 17, 2025
Rollup of 12 pull requests Successful merges: - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - #143271 (Store the type of each GVN value) - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - #143719 (Emit warning when there is no space between `-o` and arg) - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - #143891 (Port `#[coverage]` to the new attribute system) - #143967 (constify `Option` methods) - #144008 (Fix false positive double negations with macro invocation) - #144010 (Boostrap: add warning on `optimize = false`) - #144034 (tests: Test line number in debuginfo for diverging function calls) - #144049 (rustc-dev-guide subtree update) - #144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 18, 2025
…e1-dead constify `Option` methods r? ````@fee1-dead```` tracking issue: rust-lang#143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 18, 2025
…e1-dead constify `Option` methods r? `````@fee1-dead````` tracking issue: rust-lang#143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 18, 2025
…e1-dead constify `Option` methods r? ``````@fee1-dead`````` tracking issue: rust-lang#143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
bors added a commit that referenced this pull request Jul 18, 2025
Rollup of 11 pull requests Successful merges: - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - #143271 (Store the type of each GVN value) - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - #143719 (Emit warning when there is no space between `-o` and arg) - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - #143891 (Port `#[coverage]` to the new attribute system) - #143967 (constify `Option` methods) - #144008 (Fix false positive double negations with macro invocation) - #144010 (Boostrap: add warning on `optimize = false`) - #144049 (rustc-dev-guide subtree update) - #144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
@bors bors merged commit a7009e9 into rust-lang:master Jul 18, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 18, 2025
rust-timer added a commit that referenced this pull request Jul 18, 2025
Rollup merge of #143967 - oli-obk:const-option-methods, r=fee1-dead constify `Option` methods r? ```````@fee1-dead``````` tracking issue: #143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jul 19, 2025
Rollup of 11 pull requests Successful merges: - rust-lang/rust#142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - rust-lang/rust#143271 (Store the type of each GVN value) - rust-lang/rust#143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - rust-lang/rust#143719 (Emit warning when there is no space between `-o` and arg) - rust-lang/rust#143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - rust-lang/rust#143891 (Port `#[coverage]` to the new attribute system) - rust-lang/rust#143967 (constify `Option` methods) - rust-lang/rust#144008 (Fix false positive double negations with macro invocation) - rust-lang/rust#144010 (Boostrap: add warning on `optimize = false`) - rust-lang/rust#144049 (rustc-dev-guide subtree update) - rust-lang/rust#144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jul 21, 2025
Rollup of 11 pull requests Successful merges: - rust-lang/rust#142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - rust-lang/rust#143271 (Store the type of each GVN value) - rust-lang/rust#143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - rust-lang/rust#143719 (Emit warning when there is no space between `-o` and arg) - rust-lang/rust#143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - rust-lang/rust#143891 (Port `#[coverage]` to the new attribute system) - rust-lang/rust#143967 (constify `Option` methods) - rust-lang/rust#144008 (Fix false positive double negations with macro invocation) - rust-lang/rust#144010 (Boostrap: add warning on `optimize = false`) - rust-lang/rust#144049 (rustc-dev-guide subtree update) - rust-lang/rust#144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
Muscraft pushed a commit to Muscraft/rust that referenced this pull request Jul 21, 2025
…e1-dead constify `Option` methods r? ```````@fee1-dead``````` tracking issue: rust-lang#143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
Muscraft pushed a commit to Muscraft/rust that referenced this pull request Jul 21, 2025
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - rust-lang#143271 (Store the type of each GVN value) - rust-lang#143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - rust-lang#143719 (Emit warning when there is no space between `-o` and arg) - rust-lang#143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - rust-lang#143891 (Port `#[coverage]` to the new attribute system) - rust-lang#143967 (constify `Option` methods) - rust-lang#144008 (Fix false positive double negations with macro invocation) - rust-lang#144010 (Boostrap: add warning on `optimize = false`) - rust-lang#144049 (rustc-dev-guide subtree update) - rust-lang#144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Jul 29, 2025
…e1-dead constify `Option` methods r? ```````@fee1-dead``````` tracking issue: rust-lang#143956 these unblock making `PartialOrd` and `Ord` const without resorting to inlining some of these at call sites.
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.

4 participants