Skip to content

Conversation

alex-semenyuk
Copy link
Member

@alex-semenyuk alex-semenyuk commented Jun 19, 2022

changelog: More info on NEEDLESS_OPTION_TAKE

@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 @Jarcho (or someone else) soon.

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 Jun 19, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Jun 19, 2022

Can you expand on why calling take is redundant rather than just stating that it is.

@alex-semenyuk
Copy link
Member Author

Can you expand on why calling take is redundant rather than just stating that it is.

@Jarcho added more details.

@Jarcho
Copy link
Contributor

Jarcho commented Jun 22, 2022

Usually the Why is this bad? section is just one or two sentences unless there are subtleties that require more explanation. A detailed step-by-step breakdown isn't usually needed. I should have been more clear about the level of detail needed here.

Your explanation is also missing why x.as_ref().take() should be linted, but x.take() is fine. You covered that take returns the input value, but not why take does nothing after as_ref.

@alex-semenyuk
Copy link
Member Author

@Jarcho Thanks for review!
My intention was to show that the result x.as_ref() and x.as_ref().take() are the same, that's why take() after x.as_ref() is needless. As for size it's actually few sentences if remove example.

@Jarcho
Copy link
Contributor

Jarcho commented Jun 24, 2022

Between the example code and the type listing of every expression there's a lot of extra detail in the explanation. Only two points are required for understanding why .as_ref().take() is redundant.

  • take is modifying the value returned by as_ref, which is a new, temporary value.
  • take returns the value passed in as it's argument.

Anything not related to those two points ends up as a distraction from them.

As an example, the last line along with steps three and four are the only parts needed to point out they return the same value. The rest of it ends up getting in the way of seeing what the main point is.

Comment on lines 2231 to 2236
/// ### Why is this bad?
/// Redundant code.
/// ```ignore
/// let x = Some(2);
/// let y = x.as_ref().take();
/// ```
Copy link
Member

@flip1995 flip1995 Jun 28, 2022

Choose a reason for hiding this comment

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

This section should conceptually explain why this is bad, rather than with examples. If the examples are not good enough, please add better examples in the Examples section. But I would prefer to keep this section free of code examples for all lints (there are always exceptions of course).

Copy link
Member Author

Choose a reason for hiding this comment

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

@flip1995 updated

@alex-semenyuk alex-semenyuk force-pushed the needless_option_take_more_docs branch from 1b80081 to 340e5fb Compare June 28, 2022 13:56
@alex-semenyuk
Copy link
Member Author

@Jarcho updated

@Jarcho
Copy link
Contributor

Jarcho commented Jun 30, 2022

That is an improvement with the extra focus. This can be further simplified to just the last sentence. It's enough to just state that the results are the same without walking through the types involved.

You need to add something about take writing None to it's argument. In this case the modification is useless as it's to a temporary that cannot be read from afterwards.

NEEDLESS_OPTION_TAKE doc improvements

NEEDLESS_OPTION_TAKE doc improvements

NEEDLESS_OPTION_TAKE doc improvements

NEEDLESS_OPTION_TAKE doc improvements

NEEDLESS_OPTION_TAKE doc improvements

NEEDLESS_OPTION_TAKE doc improvements

NEEDLESS_OPTION_TAKE doc improvements
@alex-semenyuk alex-semenyuk force-pushed the needless_option_take_more_docs branch from 9181c5b to e780435 Compare July 17, 2022 13:17
@alex-semenyuk
Copy link
Member Author

@Jarcho ok

@Jarcho
Copy link
Contributor

Jarcho commented Jul 17, 2022

Looks good. Thank you for catching the missing docs.

@bors r+

@bors
Copy link
Contributor

bors commented Jul 17, 2022

📌 Commit e780435 has been approved by Jarcho

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 17, 2022

⌛ Testing commit e780435 with merge 3a4e457...

@bors
Copy link
Contributor

bors commented Jul 17, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Jarcho
Pushing 3a4e457 to master...

@bors bors merged commit 3a4e457 into rust-lang:master Jul 17, 2022
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.

5 participants