Skip to content

fallible_int_fallback: cover unwrap_or_else + add UI test#1

Merged
Andrew Gazelka (andrewgazelka) merged 1 commit into
mainfrom
andrewgazelka/fallible-int-fallback-unwrap-or-else
Jun 5, 2026
Merged

fallible_int_fallback: cover unwrap_or_else + add UI test#1
Andrew Gazelka (andrewgazelka) merged 1 commit into
mainfrom
andrewgazelka/fallible-int-fallback-unwrap-or-else

Conversation

@andrewgazelka

@andrewgazelka Andrew Gazelka (andrewgazelka) commented Jun 5, 2026

Copy link
Copy Markdown
Member

Extends the existing fallible_int_fallback restriction lint to also catch .unwrap_or_else(..) (it already caught .unwrap_or / .unwrap_or_default) on a Result<_, TryFromIntError>, since all three silently substitute a default for an out-of-range integer conversion.

  • type-aware: only fires when the receiver Result's Err is TryFromIntError, so Option::unwrap_or and unrelated Results are untouched
  • sharper message + help (default hides the overflow; propagate, explicit documented clamp, or #[allow] with a reason)
  • new UI test covering all three methods + the try_into() form, with negative cases that must not fire
  • minor cleanup in the touched file (drop an em dash, use Ty unqualified for the internal dogfood lint)

Validated locally on the pinned toolchain: cargo build clean, TESTNAME=fallible_int_fallback cargo uitest passes (5 expected hits, 0 false positives).

Made with Claude (Opus 4.8).

Note

Extend fallible_int_fallback lint to cover unwrap_or_else and add UI tests

  • Adds unwrap_or_else to the set of methods that trigger the FALLIBLE_INT_FALLBACK lint, alongside unwrap_or and unwrap_or_default, when the receiver is Result<_, TryFromIntError>.
  • Updates the diagnostic message to state that the call "silently substitutes a default for an out-of-range integer conversion, hiding the overflow", with updated help text recommending explicit clamping or error propagation.
  • Adds a UI test in fallible_int_fallback.rs covering all three triggering methods plus non-triggering cases (Option, non-TryFromIntError Results, explicit clamping, infallible conversions).

Macroscope summarized 3112419.

The lint already fired on .unwrap_or / .unwrap_or_default on a
Result<_, TryFromIntError>; extend it to .unwrap_or_else, which silently
substitutes a value the same way. Sharpen the message/help to say the
default hides the overflow and how to fix it (propagate, explicit clamp,
or allow-with-reason). Add a UI test covering all three methods plus the
try_into() form, and negative cases (Option::unwrap_or, a non-int-error
Result, an explicit min-then-cast). Drop a stray em dash and use Ty
unqualified to satisfy the internal dogfood lint.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

Lintcheck changes for 3112419

Lint Added Removed Changed
clippy::fallible_int_fallback 0 0 1

This comment will be updated if you push new changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant