-
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
auto-fix for redundant_else
lint
#13936
base: master
Are you sure you want to change the base?
auto-fix for redundant_else
lint
#13936
Conversation
e395c27
to
8ade7a6
Compare
What if the For example, the PR fails with this code: fn with_drop(t: bool) -> u32 {
let a = 42;
if t {
return 0;
} else {
let a = "foobar";
println!("this a = {a}");
}
a + 1
} because Maybe the suggestion should apply only when no bindings are introduced inside the |
Another (very minor) issue is that if the fix belongs to a macro, the indentation shown will be the one of the macro call, not the proper one, e.g., macro_rules! mac {
($t:expr) => {{
if $t {
return 0;
} else {
return 42;
}
}}
}
fn call_macro() -> u32 {
mac!(true)
} will suggest using macro_rules! mac {
($t:expr) => {{
if $t {
return 0;
}
return 42;
}}
} |
f397659
to
edf3828
Compare
indent_relative_to: Option<Span>, | ||
) -> Cow<'a, str> { | ||
let extracted = extract_else_block(&snippet(cx, els_span, default)); | ||
let indent = indent_relative_to.and_then(|s| indent_of(cx, s)); |
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.
@samueltardieu As you point out, the indentation of the suggestion would be the same as the indentation of the macro invocation in this implementation. However, I wonder if there is a solution for this since Clippy can only know the structure after the macro has been expanded...
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 is why I said this was a very minor nit: I don't think it is important to fix, and I'm not sure it is easy to do so.
redundant_else
can be fixed automatically.changelog: [
redundant_else
]: auto-fix when appropriate