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

Add clippy::result_as_ref_deref lint #13474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aleksanderkrauze
Copy link

changelog: added new lint result_as_ref_deref

closes #13342

I've added new lint result_as_ref_deref, which mirrors already existing lint option_as_ref_deref and reused its existing check function.

Open question is should this be another lint, or should two of them be merged together? I've asked about it in the original issue (proposing manual_as_ref_deref name), and @Jarcho suggested the same thing (and proposed manual_fallible_as_deref name).

I'm not sure what is clippy's policy regarding renaming lint names, so I opted into just adding new lint and waiting for the review.

@rustbot
Copy link
Collaborator

rustbot commented Sep 28, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Jarcho (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 28, 2024
@aleksanderkrauze
Copy link
Author

aleksanderkrauze commented Sep 29, 2024

Uh. I think I messed something up. I've pulled master branch to be up to date, rebased my working branch on top of it, and now tests don't pass and a whole bunch of code needs to be reformatted. However when I look at the diff between my branch and upstream/master I only see my changes. Help would be appreciated. 😃

EDIT. After some more rebasing and tweaking all seams to work now. I don't know what I did previously wrong, but now CI passes.

Comment on lines +32 to 48
let target = 'target: {
let target_ty = cx.typeck_results().expr_ty(as_ref_recv);
if is_type_diagnostic_item(cx, target_ty, sym::Option) {
break 'target Target::Option;
}
if is_type_diagnostic_item(cx, target_ty, sym::Result) {
break 'target Target::Result;
}
return;
};

if target == Target::Option && !msrv.meets(msrvs::OPTION_AS_DEREF) {
return;
}
if target == Target::Result && !msrv.meets(msrvs::RESULT_AS_DEREF) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Using get_type_diagnostic_name() would let you simplify this part:

    let target_ty = cx.typeck_results().expr_ty(as_ref_recv);
    let target = match get_type_diagnostic_name(cx, target_ty) {
        Some(sym::Option) if msrv.meets(msrvs::OPTION_AS_DEREF) => Target::Option,
        Some(sym::Result) if msrv.meets(msrvs::RESULT_AS_DEREF) =>Target::Result,
        _ => return,
    };

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.

Add result_as_ref_deref lint
4 participants