Skip to content

feat(num): improve error messages for TryFromIntError#156225

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
sorairolake:improve-try-from-int-error-description
Jul 21, 2026
Merged

feat(num): improve error messages for TryFromIntError#156225
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
sorairolake:improve-try-from-int-error-description

Conversation

@sorairolake

@sorairolake sorairolake commented May 6, 2026

Copy link
Copy Markdown
Contributor

This pull request improves the Display trait implementation for TryFromIntError by providing more specific error messages based on the underlying IntErrorKind.

Currently, the error message is always "out of range integral type conversion attempted". This makes debugging difficult because users cannot distinguish the detailed cause of the error from the error message.

IntErrorKind::Empty and IntErrorKind::InvalidDigit should be unreachable.

I don't think this is breaking changes, because similar changes were made in the past in #96168.

See also: https://users.rust-lang.org/t/are-changes-to-fmt-display-considered-breaking/59775

Change to display more detailed error messages based on `IntErrorKind`.
@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 May 6, 2026
@rustbot

rustbot commented May 6, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e, scottmcm

@sorairolake

Copy link
Copy Markdown
Contributor Author

@rustbot label +T-libs-api -T-libs
r? libs-api

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 6, 2026
@rustbot rustbot assigned dtolnay and unassigned Mark-Simulacrum May 6, 2026

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dtolnay

dtolnay commented Jul 21, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 0229150 has been approved by dtolnay

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 21, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #155617 (Replace `jemalloc` bootstrap options with `override-allocator`)
 - #156225 (feat(num): improve error messages for `TryFromIntError`)
 - #159058 (implement #![feature(macroless_generic_const_args)])
 - #159435 (core: implement `Rng` for references)
 - #159471 (Make `Global` and `System` allocators unstably implement `const Clone + const Default`.)
 - #159590 (Remove some dead code)
 - #159636 (Improve some comments (and an error message))
@rust-bors
rust-bors Bot merged commit 8b7e46a into rust-lang:main Jul 21, 2026
11 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 21, 2026
rust-timer added a commit that referenced this pull request Jul 21, 2026
Rollup merge of #156225 - sorairolake:improve-try-from-int-error-description, r=dtolnay

feat(num): improve error messages for `TryFromIntError`

- Tracking issue: #153978

This pull request improves the `Display` trait implementation for `TryFromIntError` by providing more specific error messages based on the underlying `IntErrorKind`.

Currently, the error message is always `"out of range integral type conversion attempted"`. This makes debugging difficult because users cannot distinguish the detailed cause of the error from the error message.

`IntErrorKind::Empty` and `IntErrorKind::InvalidDigit` should be unreachable.

I don't think this is breaking changes, because similar changes were made in the past in #96168.

See also: <https://users.rust-lang.org/t/are-changes-to-fmt-display-considered-breaking/59775>
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jul 23, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#155617 (Replace `jemalloc` bootstrap options with `override-allocator`)
 - rust-lang/rust#156225 (feat(num): improve error messages for `TryFromIntError`)
 - rust-lang/rust#159058 (implement #![feature(macroless_generic_const_args)])
 - rust-lang/rust#159435 (core: implement `Rng` for references)
 - rust-lang/rust#159471 (Make `Global` and `System` allocators unstably implement `const Clone + const Default`.)
 - rust-lang/rust#159590 (Remove some dead code)
 - rust-lang/rust#159636 (Improve some comments (and an error message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants