-
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
brace_style not implemented, among other things #5433
Comments
Thanks for reaching out. As a general ask/recommendation, it's a lot easier to share, review, and discuss specifics in focused conversation, with as minimal a repro as possible (both config and code) and to try to refrain from a catch-all set of issues/questions. Given that you started the title and initial question relative to the Myself or someone else will try to take a closer look at the "other things" as you put it 😄 when time permits, but in the interim if you have the time, it would speed things along if you could try to reduce down the set of config options to the subset that are producing the problem you are experiencing |
Turns out this is the same root issue as #5431 |
Why was this the go-to implementation of a feature called |
I'd encourage you read through the discussion in the issue I linked in my last comment, where the name of the still-unstable option is an explicit discussion point. Also keep in mind that while some users, perhaps including yourself, may want a categorical application of brace styling, there's plenty of others that want different behavior depending on the context (e.g. items vs patterns vs expressions). In these scenarios it's best for us to try to support the community at large instead of trying to pick one camp at the expense of another. Your second sentence is tantamount to "why wasn't the entire product implemented in a completely different manner", which isn't a topic that's really worth debating at this point, but in general: there's two typical flavors of code formatters, one which follows the token processing and matching from the source file as you describe, and the other that deals with parsing the input and formatting the AST representation of the program against a set of rules (a pretty-printer). The latter is the approach the Rust community took many, many years ago and is not going to change. There's benefits and tradeoffs to each approach, but the AST pretty-printer approach was taken because it was the best solution to achieve Rust's goals of having a unified default style for Rust code across codebases and to best support the more advanced types of syntactical transformations and restructuring that the community wanted. That default style is codified in the Rust Style Guide, rustfmt is simply the implementing tool, where we've also added configuration options to allow folks to get results that differ from those codified prescriptions. |
I appreciate the very well thought-out reply. I hope I didn't come across as rude. I actually did read the discussion before making the issue here, but not so closely that I remembered that talking point. I was just trying to figure out what's been going on since 2020 when someone commented on closures and such. I completely agree that having fine-tuned behavior per syntactical construct is the optimal solution. I didn't mean to imply that the ideal solution was a one-size-fits-all setting |
No worries, and no rudeness whatsoever, just wanted to make sure you'd seen the other thread. Certainly feel free to ask any questions (there or here) if anything is unclear; I realize some of the discussion over there may presume some inherent knowledge of rustfmt usage that's not necessarily obvious to those new to the tool.
Starting with the last one first, that would be fantastic! We've probably got some decent issues in this repository that relatively simple and perhaps a good way to get some Rust practice in. As to the other points, which share a general theme, this basically just boils down to the basics of open source volunteerism and workloads/priorities vs bandwidth constraints. rustfmt's core goal is to format Rust code according to the style guide as we were discussing earlier, and there's more than enough work on that front to occupy the entirety of the bandwidth of the rustfmt team. Config options exist to allow users to do something that diverges from that core goal, because they are all about formatting code in ways that's different from the style guide. As such that takes a priority backseat by default, and that's why we typically don't do much work on config options ourselves these days (though there's occasionally exceptions as and when an option has strong alignment to some other goals). Most often, new config options get added by someone from the community when there's a different style they want badly enough that they are willing to contribute themselves, and the same type of pattern largely holds true for stabilization (someone sufficiently motivated to have an option available on stable for their usage). The difference with stabilization is that a lot more users are on nightly toolchains than one might suspect, so the potential pool of users is even smaller compared to the existence/adding of a new option. We assist users on both fronts, but it's just rarely something we drive ourselves. Additionally,
Nope, your assumption is incorrect (fortunately!). I spoke to this in #3376 (comment), but that same type of pattern of having one top-level option that controls everything, but which also influences/works with more granular options is not only possible, it's actually something we've already done before in other cases. (edit: typo fixes) |
rustfmt.toml
main.rs
How?
This is after
cargo fmt
. I don't know why it gets it so wrong. Why is it not even enforcing indentation? Why are the braces not on the next line according tobrace_style = "AlwaysNextLine"
? Why islorem
not condensed onto one line according tostruct_lit_single_line = true
? Why does it not put spaces around characters like:
or=
? Why does it not remove superfluous parentheses on line 28? This is on the latest nightly. I assume I'm doing something wrong.The text was updated successfully, but these errors were encountered: