Skip to content

Tracking Issue for const_ops #143802

Open
Open

Description

@RalfJung

Feature gate: #![feature(const_ops)]

This is a tracking issue for const-stability of traits in ops.

Public API

// core::ops

#[const_trait]
pub trait Add<Rhs = Self> { ... }

#[const_trait]
pub trait Sub<Rhs = Self> { ... }

#[const_trait]
pub trait Mul<Rhs = Self> { ... }

#[const_trait]
pub trait Div<Rhs = Self> { ... }

#[const_trait]
pub trait Rem<Rhs = Self> { ... }
  • Neg
  • Not
  • BitAnd
  • BitOr
  • BitXor
  • Shl
  • Shr
  • AddAssign
  • SubAssign
  • MulAssign
  • DivAssign
  • RemAssign
  • BitAndAssign
  • BitOrAssign
  • BitXorAssign
  • ShlAssign
  • ShrAssign

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions / Blockers

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jul 11, 2025
  2. added a commit that references this issue on Jul 12, 2025
  3. added a commit that references this issue on Jul 13, 2025
  4. added a commit that references this issue on Jul 13, 2025
  5. clarfonthey commented on Jul 14, 2025

    @clarfonthey
    Contributor

    Gonna tackle making the rest of the relevant traits in core::ops const. Previously, I was going to split this into const_arith_ops and const_bit_ops, but per recommendation, I've un-split them, meaning that no split is going to happen.

    EDIT: Will include a full list of changes in attached PR, but it's worth noting the relevant traits that will be added to this tracking issue:

    • Neg
    • Not
    • BitAnd
    • BitOr
    • BitXor
    • Shl
    • Shr
    • AddAssign
    • SubAssign
    • MulAssign
    • DivAssign
    • RemAssign
    • BitAndAssign
    • BitOrAssign
    • BitXorAssign
    • ShlAssign
    • ShrAssign

    Additionally, besides the current implementations for primitives, it will include implementations for Duration, Ipv[46]Addr, references of primitives, Wrapping, and Saturating, since all of those implementations depend on already-const-stable methods and just needed to be marked const with the appropriate stability attribute.

    In particular, I suspect that the Assign variants were omitted back when these traits were originally constified because mutable references weren't stable in const context yet, but they now are, so, there's no reason to not include them as well since most of them are just simple *self = *self op rhs impls anyway.

  6. fee1-dead commented on Jul 20, 2025

    @fee1-dead
    Member

    Previously, I was going to split this into const_arith_ops and const_bit_ops, but per recommendation, I've un-split them, meaning that no split is going to happen.

    I don't think a split is necessary here. I think if we were to stablize it we'd likely stabilize them altogether.

  7. added a commit that references this issue on Jul 21, 2025
  8. added 3 commits that reference this issue on Aug 10, 2025
  9. clarfonthey commented on Aug 11, 2025

    @clarfonthey
    Contributor

    #143949 is now merged, so, the issue description needs to be updated. Full list of changes is in the PR description.

  10. added a commit that references this issue on Aug 11, 2025
  11. clarfonthey commented on Aug 12, 2025

    @clarfonthey
    Contributor

    Also highlighting @Zalathar's comment on #143949, which indicated that a perf regression showed up merging these changes: #145236 (comment)

    This shouldn't affect perf, but since these operations on primitives were all const despite the traits not being implemented anyway, perhaps they're going through the traits now which is slower? I have absolutely no idea what the actual issue is here, but I figured that I'd share on the tracking issue since the PR is now merged.

  12. added a commit that references this issue on Aug 13, 2025
  13. rustbot commented on Aug 29, 2025

    @rustbot
    Collaborator

    Error: Label since can only be set by Rust team members

    Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

  14. scimind2460 commented on Sep 13, 2025

    @scimind2460
    Contributor

    Since @clarfonthey has made the PR for the remaining impls (#143949), can't we check this off?

  15. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions