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 lint 'ref_option_ref' #1377 #6165

Merged
merged 16 commits into from
Nov 3, 2020
Merged

Conversation

dvermd
Copy link
Contributor

@dvermd dvermd commented Oct 12, 2020

This lint checks for usage of &Option<&T> which can be simplified as Option<&T> as suggested in #1377.

This WIP PR is here to get feedback on the lint as there's more cases to be handled:

  • statics/consts,
  • associated types,
  • type alias,
  • function/method parameter/return,
  • ADT definitions (struct/tuple struct fields, enum variants)

changelog: Add 'ref_option_ref' lint

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @flip1995 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 12, 2020
@dvermd dvermd force-pushed the ref_option_ref branch 8 times, most recently from 5bd90ed to 8ec9b1d Compare October 16, 2020 21:57
@dvermd dvermd changed the title WIP: Add lint 'ref_option_ref' #1377 Add lint 'ref_option_ref' #1377 Oct 16, 2020
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

I don't think it matters where this pattern occurs and we can lint in any case. Except, we have to be careful in public item signatures, like functions, structs, statics, consts, ...

The simplest way to deal with this is to add check_item and check_item_post and set a flag in your lint struct, if we're in a public item. This will introduce FNs in bodies of public functions. You can try to deal with that yourself in this PR or just write it as a known FN in the Known Problems section and leave it up for future folks.

clippy_lints/src/ref_option_ref.rs Outdated Show resolved Hide resolved
clippy_lints/src/ref_option_ref.rs Outdated Show resolved Hide resolved
@flip1995 flip1995 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 Oct 17, 2020
@dvermd
Copy link
Contributor Author

dvermd commented Oct 19, 2020

I added some limitations to the Know Problems section as advised.

@dvermd dvermd requested a review from flip1995 October 19, 2020 20:21
@dvermd dvermd requested a review from flip1995 October 20, 2020 05:26
@bors
Copy link
Collaborator

bors commented Oct 24, 2020

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

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

dvermd and others added 5 commits October 26, 2020 22:34
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: Philipp Krones <hello@philkrones.com>
@dvermd
Copy link
Contributor Author

dvermd commented Oct 26, 2020

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@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 Oct 26, 2020
@dvermd dvermd requested a review from flip1995 October 28, 2020 21:34
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

Only a little formatting left to do.

clippy_lints/src/ref_option_ref.rs Outdated Show resolved Hide resolved
@dvermd dvermd requested a review from flip1995 October 30, 2020 20:25
@flip1995
Copy link
Member

flip1995 commented Nov 3, 2020

@bors r+

Thanks!

@bors
Copy link
Collaborator

bors commented Nov 3, 2020

📌 Commit 7b065db has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Nov 3, 2020

⌛ Testing commit 7b065db with merge 2fe87a8...

@bors
Copy link
Collaborator

bors commented Nov 3, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 2fe87a8 to master...

@bors bors merged commit 2fe87a8 into rust-lang:master Nov 3, 2020
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.

None yet

5 participants