Skip to content

Document arithmetic operations on Instant #45448

Open

Description

@bluss

Some questions that have come up about using Instants:

  1. What meaning does Instant -= Duration have?
  2. What are the preconditions on the instant and the duration, so that it does not panic or cause arithmetic overflow assertions? One user noticed that instant -= duration can trip this assertion (specifically on Windows).

Activity

  1. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    T-libs-api[DEPRECATED; DO NOT USE]
    on Oct 22, 2017
  2. retep998 commented on Oct 24, 2017

    @retep998
    Contributor

    The zero point of Instant is not specified and could be any time before the start of the process. If you want to ensure that you do not get any underflow errors, then do not attempt to create an Instant representing a time before the process was spawned.

  3. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Oct 24, 2017
  4. removed
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on Jan 10, 2019
  5. steveklabnik commented on Jan 10, 2019

    @steveklabnik
    Contributor

    @rust-lang/libs: if you can articulate which aspects of this API are guaranteed, I'm happy to document them.

  6. sfackler commented on Jan 10, 2019

    @sfackler
    Member
    1. What meaning does Instant -= Duration have?

    It causes Instant to have the value of an Instant created Duration time before its original value.

    1. What are the preconditions on the instant and the duration, so that it does not panic or cause arithmetic overflow assertions?

    Instant currently wraps the platform-specific monotonic time type, so the overflow bounds depend on the system. Some probably safe assumptions would be to not create Instants from before your process started or Instants more than a century or so in the future. I don't know what we specifically want to guarantee here though.

  7. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    and removed
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on May 15, 2022
  8. added a commit that references this issue on Dec 11, 2025
  9. added a commit that references this issue on Dec 12, 2025
  10. added a commit that references this issue on Dec 13, 2025
  11. added 2 commits that reference this issue on Dec 13, 2025
  12. added 3 commits that reference this issue on Dec 14, 2025
  13. added a commit that references this issue on Dec 14, 2025
  14. 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

    A-timeArea: `std::time`C-enhancementCategory: An issue proposing an enhancement or a PR with one.P-mediumMedium priorityT-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