-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
improve the suggestion of the lint unit-arg
#5931
Conversation
r? @phansch (rust_highfive has picked a reviewer for you, use r? to override) |
r? @flip1995 Since I produced the latest (problematic) suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for further improving the suggestion! Only one case is indented weirdly now.
tests/ui/unit_arg.stderr
Outdated
LL | foo(0); | ||
LL | foo(1); | ||
LL | }; { | ||
LL | foo(2); | ||
LL | foo(3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is still an indentation issue I must handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, except one code-style thing.
clippy_lints/src/types.rs
Outdated
let wrap_in_block = | ||
!matches!(parent_node, Some(Node::Block(_))) && !matches!(parent_node, Some(Node::Stmt(_))); | ||
|
||
let stmts_indent = if wrap_in_block { indent + 4 } else { indent }; | ||
let mut stmts_and_call = arg_snippets_without_empty_blocks.clone(); | ||
stmts_and_call.push(expr_with_replacements); | ||
let mut stmts_and_call_str = stmts_and_call | ||
.into_iter() | ||
.enumerate() | ||
.map(|(i, v)| { | ||
let with_indent_prefix = if i > 0 { " ".repeat(stmts_indent) + &v } else { v }; | ||
trim_multiline(with_indent_prefix.into(), true, Some(stmts_indent)).into_owned() | ||
}) | ||
.collect::<Vec<String>>() | ||
.join(";\n"); | ||
|
||
if wrap_in_block { | ||
stmts_and_call_str = " ".repeat(stmts_indent) + &stmts_and_call_str; | ||
stmts_and_call_str = format!("{{\n{}\n{}}}", &stmts_and_call_str, " ".repeat(indent)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to wrap this wrap_in_block
handling code into its own function to get rid of the allow
above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved that logic out. That clarifies the code a bit 👍.
I had to modify and rename the trim_multiline
utils method to let it indent code further as it only supported dedentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case you missed the notif @flip1995 (sorry if have no time atm)
@bors r+ Thanks! And sorry for the late reply |
📌 Commit b220ddf has been approved by |
improve the suggestion of the lint `unit-arg` Fixes #5823 Fixes #6015 Changes ``` help: move the expression in front of the call... | 3 | g(); | help: ...and use a unit literal instead | 3 | o.map_or((), |i| f(i)) | ``` into ``` help: move the expression in front of the call and replace it with the unit literal `()` | 3 | g(); | o.map_or((), |i| f(i)) | ``` changelog: improve the suggestion of the lint `unit-arg`
💔 Test failed - checks-action_test |
@bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #5823
Fixes #6015
Changes
into
changelog: improve the suggestion of the lint
unit-arg