Skip to content
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

switch to non-recursive mode by default #3938

Merged
merged 4 commits into from Dec 9, 2019

Conversation

@calebcartwright
Copy link
Contributor

calebcartwright commented Nov 22, 2019

Resolves #3587 and refs #3887

This PR updates the default mode of rustfmt to not format submods in external files, with an accompanying new CLI arg (--recursive)/config option to enable recursive submod formatting mode (which was the default behavior of rustfmt 1.x).

cargo fmt behavior remains unchanged, as cargo fmt will automatically pass the --recursive flag to rustfmt.

I went ahead and marked the new recursive config option as stable because it is relatively simple. Also because it would be pretty weird IMO if both recursive and skip_children were only available on nightly, especially with skip_children now deprecated (that would make it impossible to format sub mods on stable).

Lastly, I did a bit of refactoring in cargo fmt to consolidate/simplify the adding of args to rustfmt (for example the transformation of --message-format to --emit .. for rustfmt, --check, etc.) which had been discussed on some earlier threads.

@calebcartwright calebcartwright force-pushed the calebcartwright:non-recursive-default branch from 39b65f2 to fe5f668 Nov 22, 2019
Configurations.md Outdated Show resolved Hide resolved
src/bin/main.rs Outdated Show resolved Hide resolved
src/cargo-fmt/main.rs Outdated Show resolved Hide resolved
src/bin/main.rs Outdated Show resolved Hide resolved
@calebcartwright

This comment has been minimized.

Copy link
Contributor Author

calebcartwright commented Nov 24, 2019

Thanks for the feedback @scampi!

Copy link
Collaborator

topecongiro left a comment

Thank you for the PR!

@@ -1720,6 +1720,14 @@ fn example() {
}
```

## `recursive`

This comment has been minimized.

Copy link
@topecongiro

topecongiro Nov 27, 2019

Collaborator

We should consider recursive as one of the internal options. We do not want users to add this to the configuration by themselves.

This comment has been minimized.

Copy link
@calebcartwright

calebcartwright Nov 27, 2019

Author Contributor

Will do 👍, though out of curiosity, why should this be a CLI only flag for users?

One downside I see with exposing recursive as a config option is that recursive = false in the config file would functionally be ignored when using cargo fmt since cargo fmt will always pass --recursive flag to rustfmt which will always take precedence over the config file value (which could be confusing for users).

This comment has been minimized.

Copy link
@topecongiro

topecongiro Nov 28, 2019

Collaborator

The options in the configuration file are meant to be persistent, whereas recursive is more of a one-shot configuration, which best suits as a CLI flag.

This comment has been minimized.

Copy link
@calebcartwright

calebcartwright Nov 28, 2019

Author Contributor

Makes sense to me! It wouldn't surprise me if there is a future request to support recursive as a config option since skip_children was available, but there's clearly several good reasons why recursive should be internal/cli-only.

Side note, while making recursive internal I noticed that internal options added to the config file seem to just be silently ignored. Do I have that correct?

If they are silently ignored:

Is that the desired behavior or would it beneficial to emit a warning ("Warning: Unknown configuration option ..)? Would that potential change be tackled (perhaps it already is) as part of #3873 or should I open a new issue?

This comment has been minimized.

Copy link
@topecongiro

topecongiro Dec 9, 2019

Collaborator

Side note, while making recursive internal I noticed that internal options added to the config file seem to just be silently ignored. Do I have that correct?

Yes.

Is that the desired behavior or would it beneficial to emit a warning ("Warning: Unknown configuration option ..)?

We should make it to a hard error rather than silently ignoring it.

Would that potential change be tackled (perhaps it already is) as part of #3873 or should I open a new issue?

This should be fixed by #3873.

Copy link
Collaborator

topecongiro left a comment

My apologies for the late review. LGTM, thank you for the update!

@topecongiro topecongiro merged commit 0a6a7d6 into rust-lang:master Dec 9, 2019
2 checks passed
2 checks passed
Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@calebcartwright calebcartwright deleted the calebcartwright:non-recursive-default branch Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.