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

feat: new lint for and_then when returning Option or Result #14050

Closed

Conversation

aaron-ang
Copy link
Contributor

@aaron-ang aaron-ang commented Jan 21, 2025

close #6436

changelog: add new return_and_then lint

Additional src files changed to reflect the lint.

@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2025

r? @Centri3

rustbot has assigned @Centri3.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 21, 2025
fn test_opt_block(opt: Option<i32>) -> Option<i32> {
let n = opt?;
let mut ret = n + 1;
ret += n;
Copy link
Contributor Author

@aaron-ang aaron-ang Jan 21, 2025

Choose a reason for hiding this comment

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

I have some difficulty generating the right format for closure blocks. see src/methods/return_and_then.rs

} else {
body_snip.trim()
};

Copy link
Contributor Author

@aaron-ang aaron-ang Jan 21, 2025

Choose a reason for hiding this comment

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

I check if the closure body contains braces and remove them. Then, I call reindent_multiline helper. However, the helper function does not properly indent lines following the first. See tests/ui.return_and_then.fixed

@aaron-ang aaron-ang closed this Jan 21, 2025
@aaron-ang aaron-ang deleted the aaron-ang/return-and-then branch January 21, 2025 06:33
@aaron-ang
Copy link
Contributor Author

aaron-ang commented Jan 21, 2025

accidentally closed PR by renaming branch, see #14051

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.

New Lint: Use question mark instead of Option::and_then
3 participants