rust-lang / rust-lang/rust

[Design] confusing `target_pointer_width = "64"` usize convertion design

Open
#138,218 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Title

confusing target_pointer_width = "64" usize convertion design

Actual

        #[cfg(target_pointer_width = "64")]
        {
            let _ = usize::try_from(42u64).unwrap();
            let _ = usize::try_from(42u32).unwrap();
            let _ = usize::from(42u16);
        }

Expected

When under target_pointer_width 64, should always success, and try is not necessary.

        #[cfg(CONDITION)]
        {
            let _ = usize::from(42u64);
            let _ = usize::from(42u32);
            let _ = usize::from(42u16);
        }

Related

https://github.com/rust-lang/rust/blob/master/library/core/src/convert/num.rs

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

Read library/core/src/convert/num.rs and inspect the existing usize conversion implementations related to target_pointer_width. Compare the requested 64-bit behavior with the current conversion design and determine the appropriate condition and API implications. Done means the design is settled and the relevant conversions have consistent, justified behavior under the requested target width.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.