Skip to content

Don't trigger unwrap_used or expect_used on uninhabited Err - #16712

Open
samueltardieu wants to merge 1 commit into
rust-lang:masterfrom
samueltardieu:features/uninhabited-types-unwrap-expect
Open

Don't trigger unwrap_used or expect_used on uninhabited Err#16712
samueltardieu wants to merge 1 commit into
rust-lang:masterfrom
samueltardieu:features/uninhabited-types-unwrap-expect

Conversation

@samueltardieu

Copy link
Copy Markdown
Member

When the Err variant is a known uninhabited type, there is no point in complaining when .unwrap() or .expect(…) are used, as they cannot fail.

One alternative would be to complain and suggest using let Ok(_) = _; which wouldn't fail either, but it may not integrate well into the code flow.

changelog: [unwrap_used] [expect_used]: do not warn on Result types whose Err variant is visibly uninhabited.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 13, 2026
@rustbot

rustbot commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator

r? @Jarcho

rustbot has assigned @Jarcho.
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: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq

@rustbot

rustbot commented Mar 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

themavik

This comment was marked as spam.

themavik

This comment was marked as low quality.

Comment thread tests/ui/unwrap_expect_used.rs
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 23, 2026
When the `Err` variant is a known uninhabited type, there is no point in
complaining when `.unwrap()` or `.expect(…)` are used, as they cannot
fail.

One alternative would be to complain and suggest using `let Ok(_) = _;` which
wouldn't fail either, but it may not integrate well into the code flow.
@samueltardieu
samueltardieu force-pushed the features/uninhabited-types-unwrap-expect branch from f40aac9 to 97b5f4a Compare June 3, 2026 18:34
@samueltardieu
samueltardieu requested a review from Jarcho June 3, 2026 18:34
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jun 3, 2026
@rustbot

rustbot commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #17369) made this pull request unmergeable. Please resolve the merge conflicts.

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants