-
Notifications
You must be signed in to change notification settings - Fork 892
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
1.x fix for missing comments extra macro body indentation #4697
1.x fix for missing comments extra macro body indentation #4697
Conversation
The When running the rustfmt bin directly, it will pick up on the rustfmt.toml config file in the root of the repository which does set this, whereas our test suites will, by design, override/set explicit config values which is why the tests are failing. Think this can be resolved by simply setting that on the config: config.set().emit_mode(config::EmitMode::Stdout);
config.set().verbose(Verbosity::Quiet);
config.set().hide_parse_errors(true);
if is_macro_def {
config.set().error_on_unformatted(true);
} |
a7c6c3f
to
4eb31fb
Compare
Thanks! Setting the config solved the issue. Note that the changes include a fix of a minor rustfmt 1.x issue: in the following code, moved the closing Lines 485 to 486 in 7de6968
|
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! Few minor things but otherwise LGTM
src/formatting.rs
Outdated
@@ -331,6 +331,9 @@ pub(crate) struct ReportedErrors { | |||
|
|||
/// Formatted code differs from existing code (--check only). | |||
pub(crate) has_diff: bool, | |||
|
|||
/// Formatted code missed something, like lost comments or extra trailing space | |||
pub(crate) has_missing_errors: bool, |
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 think we should bikeshed on the name here, as the way the name currently reads is confusing. This flag is indicator that there was something that rustfmt failed to be able to format successfully (almost always caused by the presence of a comment in a place rustfmt cannot support comments).
It's really more indicative that there were parts of the input code that rustfmt failed to format and reverted to the original formatting, so there are unformatted portions of the code in the output.
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 forgot to mention the name in the discussion, as I couldn't find a good name for both lost-comments and trailing-white-spaces errors. What about has_lost_comments_error
? has_unformatted_original_code
? Another option is to split it to has_lost_comments_error
and has_trailing_whitespaces_error
.
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'd prefer something that references "failed" or "unformatted"
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.
Renamed has_missing_errors
to has_unformatted_original_code
. Hope this is o.k.
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 don't care too much about the internal name, but do have some reservations about the public facing function given that the rustfmt lib is available for outside consumers (and we can't change it once we put it out there).
I think it's important to keep errors
in the name, so would prefer either:
(a) has_unformatted_code_errors
(b) has_unformatted_errors
(c) skip an aggregate helper, and just track/expose whitespace vs. lost comments separately (has_lost_comment_errors
and has_trailing_whitespace_errors
).
Please be sure to update the function name(s) accordingly too
54a5666
to
a3c6e73
Compare
Changed the name to |
Awesome, thank you! |
1.x fix for issue #4603 - infinite macro body indentation because of "missing comment". The fix is per the approach discussed in #4629.
As discussed, the fix includes handling both
LostComment
andTrailingWhitespace
errors, although I am not sure ifTrailingWhitespace
is needed.UPDATE: the tests fail because an issue that i cannot understand. When running
cargo make test
in my local machine it fails on the same errors. However, when running manually the created./target/debug/rustfmt
the output is o.k. I hoped that this is a problem in my local machine, but unfortunately it seems it isn't. I will be glad to get help with this issue.