-
Notifications
You must be signed in to change notification settings - Fork 898
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
silently fails to format match expression if arm pat contains comment #4119
Comments
Thanks for the report @bradjc. Looks like the problem is with the block comment in the match first match arm that's resulting in rustfmt failing to do any formatting within the match blocks (not just failing to convert the tabs). This is definitely a bug, and as a temporary workaround you may want to consider changing those two block comments on the |
1755: capsules: remove block comment, rustfmt r=ppannuto a=bradjc ### Pull Request Overview Remove a block comment to workaround a [bug](rust-lang/rustfmt#4119) in rustfmt. ### Testing Strategy This pull request was tested by travis. ### TODO or Help Wanted n/a ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make formatall`. Co-authored-by: Brad Campbell <bradjc5@gmail.com>
I've been bitten by this too. This affects both the match bodies and the match patterns. The following code is unmodified by rustfmt, and no warnings are produced:
|
Summary: Due to [rustfmt #4119](rust-lang/rustfmt#4119), comments inside pattern matches prevent formatting occurring. Move the comments so rustfmt does the right thing. Differential Revision: D25408396 fbshipit-source-id: eeab75cffd35b241640eaa22b24b0e42f3682501
I am working on this issue |
817: Clean up a lot of comments. r=Dirbaio a=Yatekii - Add spaces after the // or ///. - Add full stops. - Also quote some variable names with backticks. - Remove dead code. - Move comments that were on the same line as actual code (I consider it bad style and it breaks rustfmt rust-lang/rustfmt#4119) Co-authored-by: Noah Hüsser <yatekii@yatekii.ch> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Bug report with rustfmt will follow when I find time for it.
The presence of the comment in the middle of the pattern was triggering rust-lang/rustfmt#4119, which meant that none of the code in that match statement was being formatted by rustfmt. This commit changes the existing code to avoid triggering that bug, and also reformats the code in that block now that formatting is no longer silently failing. Change-Id: Idef7520a18a054f75adbab857823154c37fb270e Reviewed-on: https://gerrit.readyset.name/c/readyset/+/3700 Tested-by: Buildkite CI Reviewed-by: Griffin Smith <griffin@readyset.io>
I've just run into this, here's a very simple example: fn main() {
let i = 0;
match i {
0|1
// Comment!
|2|3 => {println!("<4");}
_=>unreachable!(),
}
} Removing the comment allows rustfmt to work as expected, but so long as it's there the entire match block seems to be ignored for formatting, even the entirely unrelated _ arm. Is there any update on this case? |
On a semi-related note: are there any logging/tracing options that can be enabled to emit a warning in this and similar cases (where where rustfmt silently "gives up")? |
@daprilik you can set Trying to format the code snippet from #4119 (comment) produces the following warning:
|
Some simple examples of thisThe following silently bails on the entire match statement match (a) {
0 // hello world
| 1 => (),
_ => (),
}; and so does this match (a) {
0 // hello world
=> (),
_ => (),
}; |
For Tock, we run rustfmt with Travis CI, and some PRs (example1 and example2) are passing a rustfmt check while still using tabs for indentation.
nightly-2020-03-06
andnightly-2020-04-10
.I've also tried manually running rustfmt in the relevant crate on my computer and see the same effect. Based on a question on discord, I am opening this issue.
One example (src):
Another example (src):
The text was updated successfully, but these errors were encountered: