rust-lang / rust-lang/rust

u64::saturating_div is useless

Open
#122,821 11 comments 19 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-discussion T-libs
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

pub const fn saturating_div(self, rhs: u64) -> u64

This function will panic if rhs is 0.

This makes no sense. The only way that u64 / u64 could overfllow is if rhs = 0.

The same is true for the other unsigned integer types. The signed types have the excuse that they wouldn't know whether to count division by zero as saturating to -ve or +ve maximum.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the u64::saturating_div implementation and the corresponding APIs for the other unsigned integer types. Review their documented division-by-zero behavior and the issue discussion; done requires a maintainer-approved resolution for how these APIs should behave.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.