rust-lang / rust-lang/rust

Number types' `FromStr` impl should recognize Unicode minus

Open
#130,315 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

You can say the following about the character currently exclusively recognized as minus by FromStr impls:

  • Its official Unicode name is U+002D HYPHEN-MINUS : hyphen, dash, minus sign (copied from BabelMap).
  • The general typographical reality of font designs is that it's a hyphen and not a minus sign.
  • The usage-wise reality is that it's widely used as a replacement character for a real minus sign.

In comparison, U+2212 is a dedicated minus sign:

  • Official Unicode name: U+2212 MINUS SIGN
  • Matches the horizontal bar of a plus sign.
  • GitHub, e.g., uses it to display the red "lines deleted" values. Wikipedia and LaTeX equation renderings also use it.
  • In HTML, you have the entity − for it.

Benefits of adding support:

  • If the FromStr implementations of number types (i32, f64 etc.) would support U+2212 MINUS SIGN in addition to U+002D HYPHEN-MINUS as a minus sign, UI frameworks, e.g., would have an easier time implementing text boxes that display the typographically more pleasing real minus sign, simply converting the text content to the corresponding number.
  • App implementations not further checking user input, but directly trying to parse it as a number, and banking on the returned Result, wouldn't confuse end users anymore when they pasted a number with Unicode minus into the app and the app showed an error.
  • Also, since it's a dedicated minus sign, and not just a common replacement character, it logically follows in my opinion that it should be supported.

I'm not familiar with this, but I want to point out that the Wikipedia article "Plus and minus signs" also talks about ⁒ as a minus sign (U+2052 COMMERCIAL MINUS SIGN). Perhaps, this should also be supported. But I don't know whether it's regularly set off from the number with some space character.

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 FromStr implementations for Rust's number types and their parsing tests. Determine whether support should cover U+2212 only or also U+2052, then update the relevant behavior and tests so accepted Unicode minus input parses successfully without changing unrelated formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.