-
Notifications
You must be signed in to change notification settings - Fork 888
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
Cannot set granular width configuration settings to 100% if max_width = 100
#5404
Comments
Thanks for the report! Just as a heads up, when filing an issue please try to include a minimum code example that can be used to reproduce the issue along with any configuration options needed to produce the issue. It was a little tricky to track down since I tried running rustfmt on a few files and I couldn't reproduce the error until I ran rustfmt against Running rustfmt with debug logging enabled (
Lines 483 to 486 in c4416f2
And on line 1230 we adjust the Lines 1216 to 1230 in c4416f2
rustfmt/src/config/config_type.rs Lines 89 to 103 in c4416f2
rustfmt/src/config/config_type.rs Lines 373 to 381 in c4416f2
rustfmt/src/config/config_type.rs Lines 294 to 314 in c4416f2
|
fwiw I know this has been reported before, but can't find the prior issues atm |
Wow @ytmimi, thorough research/response, thank you. I'll add the minimal repro next time. |
Hi! I can also reproduce with the following:
max_width = 100 # Not strictly necessary to reproduce.
single_line_if_else_max_width = 100 # Any value above 92 produces the incorrect warning.
macro_rules! anything { // Necessary to reproduce.
() => {};
}
fn main() {
let v = if a == b { String::new() } else { format!("anything") }; // Formatting does happen.
} The following incorrect warning is then displayed: $ cargo fmt
`single_line_if_else_max_width` cannot have a value that exceeds `max_width`. `single_line_if_else_max_width` will be set to the same value as `max_width` Although the project seems correctly formatted. Was this minimal reproductible example the only blocking point? |
Sorry If I'm late to the game, but I'm finding some inconsistency in rustfmt 1.6.0-nightly. It seems that while the value is checked as a percentage, it might be taken as the absolute value. Of course at
(So max struct literal would be 96) impl From<&Command> for CommandView {
fn from(cmd: &Command) -> Self {
Self { request_id: cmd.request_id, app_id: cmd.app_id, action: cmd.action.clone() }
}
} (line length: 92) |
@ferdonline Your issue seems unrelated to the original since it's not triggering any warning messages from rustfmt. I'm pretty sure we only set granular width settings as a percentage of |
In that case then it's only a warning problem, as it's raised when
|
@ferdonline Please open a new issue so we can discuss it separately. I'm unable to reproduce any warning messages when using I'm running:
|
I just experienced the same problem and put a few print statements into the rustfmt source code, which revealed the following behaviour: // max_width = 100
// fn_call_width = 100
macro_rules! foo {
() => {
// max_width = 92
// fn_call_width = 100
// WARNING: `fn_call_width` cannot have a value that exceeds `max_width`. `fn_call_width` will be set to the same value as `max_width`
// Which results in:
// fn_call_width = 92
};
} Notice that rustfmt decreases Interestingly, if you add an extra pair of brackets, max_width in the nested scope will be 96 instead of 92: // max_width = 100
// fn_call_width = 100
macro_rules! foo {
() => {{
// max_width = 96
// fn_call_width = 100
// WARNING: `fn_call_width` cannot have a value that exceeds `max_width`. `fn_call_width` will be set to the same value as `max_width`
// Which results in:
// fn_call_width = 96
}};
} |
Thanks for your work on rustfmt!
The granular width configuration settings are documented to be percentages of
max_width
(e.g. chain_width). However whenmax_width
is set to 100 setting their values to100
causes a warningThe error message is both surprising and incorrect since
fn_call_width = 100
is not a value that exceedsmax_width
.This does not happen if
max_width
is 99 or 101.The exact config options that trigger this bug are:
Edit by @ytmimi (add a minimal reproducible code snippet):
The text was updated successfully, but these errors were encountered: