-
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
Make it possible to correctly indent snippet_block snippets #5134
Conversation
@@ -261,7 +261,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes { | |||
_ => {}, | |||
} | |||
} | |||
let line_span = last_line_of_span(cx, attr.span); | |||
let line_span = first_line_of_span(cx, attr.span); |
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 function never returned the last line of the span, but always the first line, so I renamed it accordingly.
574d4a9
to
0c4150f
Compare
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, nice work!
if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { | ||
continue; | ||
} { | ||
println!("Blabber"); |
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 seems to be a regression as it now wraps the removed else part in a block?
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.
Yeah, it changed a little bit, but I would keep it that way for two reasons:
- It's too hard to align this correctly after removing the block
- Suggesting it like this prevents a bug, that could be produced by the suggestion:
let y: u32 = 23;
if x {
continue;
} else {
let y: u32 = 42;
// ...
}
println!("{}", y); // outputs 23
previous, the suggestion would change the output:
let y: u32 = 23; // best case: a warning for unused var is produced
if x {
continue;
}
let y: u32 = 42;
// ...
println!("{}", y); // outputs 42
now the output stays the same:
let y: u32 = 23;
if x {
continue;
}
{
let y: u32 = 42;
// ...
}
println!("{}", y); //outputs 23
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.
0c4150f
to
0fe1e3d
Compare
☔ The latest upstream changes (presumably #5125) made this pull request unmergeable. Please resolve the merge conflicts. |
666820a
to
e23881e
Compare
r=me with rebase |
@bors r=phansch |
📌 Commit e23881e has been approved by |
Make it possible to correctly indent snippet_block snippets This adds a `indent_relative_to` arg to the `{snippet,expr}_block` functions. This makes it possible to keep the correct indentation of block like suggestions. In addition, this makes the `trim_multiline` function private and adds a `indent_of` function, to get the indentation of the first line of a span. The suggestion of `needless_continue` cannot be made auto applicable, since it would be also necessary to remove code following the linted expression. (Well, maybe it is possible, but I don't know how to do it. Expanding the suggestion span to the last expression, that should be removed didn't work) changelog: Improve suggestions, when blocks of code are involved
☀️ Test successful - checks-travis, status-appveyor |
This adds a
indent_relative_to
arg to the{snippet,expr}_block
functions. This makes it possible to keep the correct indentation of block like suggestions.In addition, this makes the
trim_multiline
function private and adds aindent_of
function, to get the indentation of the first line of a span.The suggestion of
needless_continue
cannot be made auto applicable, since it would be also necessary to remove code following the linted expression. (Well, maybe it is possible, but I don't know how to do it. Expanding the suggestion span to the last expression, that should be removed didn't work)changelog: Improve suggestions, when blocks of code are involved