Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggest using if let Some(x) = arr.first() over if !arr.is_empty() then arr[0] #11858

Open
J-ZhengLi opened this issue Nov 23, 2023 · 1 comment · May be fixed by #12464
Open

suggest using if let Some(x) = arr.first() over if !arr.is_empty() then arr[0] #11858

J-ZhengLi opened this issue Nov 23, 2023 · 1 comment · May be fixed by #12464
Assignees
Labels
A-lint Area: New lints

Comments

@J-ZhengLi
Copy link
Member

J-ZhengLi commented Nov 23, 2023

What it does

Well, exactly as the title described, and could apply to whiles as well.

The idea is kinda like a combination of [unnecessary_unwrap] and [get_first].

Such lint might already exist, idk.

Advantage

Readability?

Drawbacks

maybe? maybe not?

Example

if !seq.is_empty() {
    let x = seq[0];
    // ...
}

Could be written as:

if let Some(x) = seq.first() {
    // ...
}
@J-ZhengLi J-ZhengLi added the A-lint Area: New lints label Nov 23, 2023
@Jacherr
Copy link
Contributor

Jacherr commented Mar 10, 2024

@rustbot claim

@Jacherr Jacherr linked a pull request Mar 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants