fix: respect trailing semicolon setting for last statements #6182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
#5797 fixed the trailing_semicolon rule, allowing it only for the last expression in the block. The side-effect of this change is that such snippet
will not get formatted into
(notice the
;
in thegreet
function), even thoughreturn
is the last expression here. It's happening because the implementation ofis_last_expr()
additionally checks for the type of expression for some reason unknown to merustfmt/src/stmt.rs
Lines 74 to 88 in 46e5f14
Solution
This PR fixes that by checking only the
is_last
field of theStmt
struct when deciding whether to emit the semicolon.As you can see, the example from the original PR is still not getting formatted, while the trailing comma for the last
return
statement gets removed.