Skip to content

Add Duration from nanos u128 #139243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

omanirudh
Copy link

@omanirudh omanirudh commented Apr 2, 2025

What does this PR do?

This draft PR adds the Duration::from_nanos_u128 function to handle durations that exceed the range of u64, allowing for time spans greater than ~584 years.

Motivation

The current Duration API does not support creating durations from nanoseconds represented as u128. This addition addresses that limitation.

Tracking Issue

Fixes #139201

Details

  • Introduced Duration::from_nanos_u128 as a const fn similar to other functions in the file.

  • Ensured safety by validating the nanoseconds before using unsafe code.

  • To do : complete the documentation and examples for the new function.

    r? @RalfJung

@rustbot
Copy link
Collaborator

rustbot commented Apr 2, 2025

r? @tgross35

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

@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 Apr 2, 2025
@rustbot rustbot assigned RalfJung and unassigned tgross35 Apr 2, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

RalfJung commented Apr 2, 2025

Thanks for taking this over!
However, this needs a libs reviewer. I just proposed the API. :)

r? libs

@rustbot rustbot assigned joboet and unassigned RalfJung Apr 2, 2025
@omanirudh
Copy link
Author

omanirudh commented Apr 2, 2025

Thanks for taking this over! However, this needs a libs reviewer. I just proposed the API. :)

r? libs

Happy to take this up. noted.

@tgross35
Copy link
Contributor

tgross35 commented Apr 2, 2025

@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 Apr 2, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 2, 2025

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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@omanirudh omanirudh marked this pull request as ready for review April 10, 2025 15:53
@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Apr 10, 2025
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic F-autodiff `#![feature(autodiff)]` O-hermit Operating System: Hermit O-SGX Target: SGX O-solid Operating System: SOLID O-unix Operating system: Unix-like PG-exploit-mitigations Project group: Exploit mitigations WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jun 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred in coverage instrumentation.

cc @Zalathar

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

These commits modify the library/Cargo.lock file. Unintentional changes to library/Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in match lowering

cc @Nadrieril

Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs

cc @ZuseZ4

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

rustc_macros::diagnostics was changed

cc @davidtwco, @compiler-errors, @TaKO8Ki

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred in compiler/rustc_sanitizers

cc @rcvalle

These commits modify compiler targets.
(See the Target Tier Policy.)

HIR ty lowering was modified

cc @fmease

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2025

⚠️ Warning ⚠️

@tgross35
Copy link
Contributor

@omanirudh it looks like you wound up with bad commit history somehow. You should be able to fix this by rebasing your branch, check out https://rustc-dev-guide.rust-lang.org/git.html#rebasing

@omanirudh
Copy link
Author

Re-triggering CI after rebase.
@rustbot

@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@tgross35 tgross35 removed A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-attributes Area: Attributes (`#[…]`, `#![…]`) A-meta Area: Issues & PRs about the rust-lang/rust repository itself O-SGX Target: SGX A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic PG-exploit-mitigations Project group: Exploit mitigations O-hermit Operating System: Hermit O-solid Operating System: SOLID F-autodiff `#![feature(autodiff)]` labels Jul 3, 2025
@tgross35
Copy link
Contributor

tgross35 commented Jul 3, 2025

It looks like you did a merge rather than a rebase - that will need to get fixed since this branch still contains some weird history. Were you able to try what was suggested in rustc-dev-guide (linked above)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix Operating system: Unix-like S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
9 participants