Skip to content

feat: add unnecessary literal option lint - #17819

Open
born-in-autumn wants to merge 5 commits into
rust-lang:masterfrom
born-in-autumn:master
Open

born-in-autumn wants to merge 5 commits into
rust-lang:masterfrom
born-in-autumn:master

Conversation

@born-in-autumn

@born-in-autumn born-in-autumn commented Sep 30, 2026 •

Copy link
Copy Markdown

Fixes #17808

changelog: [`unnecessary_literal_option`]: add new lint
  • Followed [lint naming conventions][lint_naming]
  • Added passing UI tests (including committed .stderr file)
  • cargo test passes locally
  • Executed cargo dev update_lints
  • Added lint documentation
  • Run cargo dev fmt

LLM disclosure: new contrbutor, everything in this PR was written manually, without LLM assistance

changelog:
The main change is the addition of a new lint, which is based onunnecessary_literal_unwrap, It adds lint suggestions for several different Option cases where the result is already known. It passes the UI tests. For naming conventions and comments, I followed existing code patterns. No extra logic was added.

Thanks for your time!

@rustbot rustbot added the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Sep 30, 2026
@rustbot

rustbot commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome!

You should hear from one of our reviewers after this PR gets at least 2 reviews from the community.

Please see the contribution instructions for more information.

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 30, 2026

@CommanderStorm CommanderStorm left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

 error: called `unwrap` on `x` after checking its variant with `is_some`
   --> tests/ui/checked_unwrap/simple_conditionals.rs:46:9
... 155 lines skipped ...
    |         ^^^^^^^^^^^^^^
 
+error: used `is_some()` on `Some` value
+  --> tests/ui/checked_unwrap/simple_conditionals.rs:45:8
+   |
+LL |     if x.is_some() {
+   |        ^^^^^^^^^^^
+   |
+help: replace this with `true`
+  --> tests/ui/checked_unwrap/simple_conditionals.rs:44:13
+   |
+LL |     let x = Some(());
+   |             ^^^^^^^^
+   = note: `-D clippy::unnecessary-literal-option` implied by `-D warnings`
+   = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_option)]`

Please go through the dogfooding errors.
You may need to expect(..) this a few times.

View changes since this review

@born-in-autumn

Copy link
Copy Markdown
Author
 error: called `unwrap` on `x` after checking its variant with `is_some`
   --> tests/ui/checked_unwrap/simple_conditionals.rs:46:9
... 155 lines skipped ...
    |         ^^^^^^^^^^^^^^
 
+error: used `is_some()` on `Some` value
+  --> tests/ui/checked_unwrap/simple_conditionals.rs:45:8
+   |
+LL |     if x.is_some() {
+   |        ^^^^^^^^^^^
+   |
+help: replace this with `true`
+  --> tests/ui/checked_unwrap/simple_conditionals.rs:44:13
+   |
+LL |     let x = Some(());
+   |             ^^^^^^^^
+   = note: `-D clippy::unnecessary-literal-option` implied by `-D warnings`
+   = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_option)]`

Please go through the dogfooding errors. You may need to expect(..) this a few times.

View changes since this review

thanks for reminding me. I spent some time fixing these CI issues.

This branch has not been deployed

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

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. 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.

3 participants