Skip to content

Add lint checking for no-op uses of Option::{as_deref,as_deref_mut} #7571

New issue

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

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

Already on GitHub? # to your account

Closed
LeSeulArtichaut opened this issue Aug 16, 2021 · 4 comments · Fixed by #7596
Closed

Add lint checking for no-op uses of Option::{as_deref,as_deref_mut} #7571

LeSeulArtichaut opened this issue Aug 16, 2021 · 4 comments · Fixed by #7596
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@LeSeulArtichaut
Copy link
Contributor

LeSeulArtichaut commented Aug 16, 2021

What it does

Checks for no-op uses of Option::{as_deref,as_deref_mut}.

Categories (optional)

  • Kind: complexity

What is the advantage of the recommended code over the original code

Removes useless code, removing clutter and improving readability.

Drawbacks

None.

Example

let a = Some(&1);
let b = a.as_deref(); // goes from Option<&i32> to Option<&i32>

Could be written as:

let a = Some(&1);
let b = a;
@LeSeulArtichaut LeSeulArtichaut added the A-lint Area: New lints label Aug 16, 2021
@LeSeulArtichaut LeSeulArtichaut changed the title Add lint checking for no-op uses of {Option,Result}::as_deref Add lint checking for no-op uses of {Option,Result}::{as_deref,as_deref_mut} Aug 16, 2021
@camsteffen camsteffen added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. good-first-issue These issues are a good way to get started with Clippy and removed E-medium Call for participation: Medium difficulty level problem and requires some initial experience. labels Aug 23, 2021
@camsteffen
Copy link
Contributor

Should be easy as two expr_ty calls and check that they are the same type.

@lengyijun
Copy link
Contributor

Result<T,E> as_deref to Result<&<T as Deref>::Target, &E>
Due to &E is not E, we shouldn't lint on Result.

@LeSeulArtichaut LeSeulArtichaut changed the title Add lint checking for no-op uses of {Option,Result}::{as_deref,as_deref_mut} Add lint checking for no-op uses of Option::{as_deref,as_deref_mut} Aug 24, 2021
@LeSeulArtichaut
Copy link
Contributor Author

@lengyijun Correct, I missed that. Edited the issue

@lengyijun
Copy link
Contributor

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants