-
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
[unstable option] brace_style #3376
Comments
Seems |
Seems |
@Sibz could you elaborate on what you mean by logic blocks, with a code snippet? If you're referring to things like |
Thank you, didn't see that one and I did scour the whole list! Mustn't have had my morning coffee. |
New structs aren't included in this let value = MyStruct {
something: 1
} vs let value = MyStruct
{
something: 1
} |
Closures are also not included in this. foo.ok_or_else(|| {
// closure
}) Should be: foo.ok_or_else(||
{
// closure
}) |
Sorry for double comment. Also does not work for macro_rules! filter_map_view {
($query:ident, $val:ident) => { Should be: macro_rules! filter_map_view
{
($query:ident, $val:ident) =>
{ |
Also doesn't work for InputUsing use ::
{
std::time::Duration,
async_std::
{
fs::remove_file,
path::Path,
task,
},
clap::
{
app_from_crate,
crate_authors,
crate_description,
crate_name,
crate_version,
Arg,
},
log::
{
error,
info,
},
}; ExpectedNo changes. Actual Resultuse ::{
async_std::{
fs::remove_file,
path::Path,
task,
},
clap::{
app_from_crate,
crate_authors,
crate_description,
crate_name,
crate_version,
Arg,
},
log::{
error,
info,
},
std::time::Duration,
}; |
At this point I think it's worth pausing to reconsider whether the current option is the right approach to meet the needs of users. For reference, this option was historically only applied to items; not in the expression nor statement contexts. control_brace_style also exists to configure the brace style on control flow type expressions. We'd started extending the option to cover a few additional expression contexts, such as on unsafe, async, and extern blocks. However, I'm increasingly getting the sense that having only one option (essentially) is unlikely to provide a sufficient amount of flexibility. I wonder if instead we might need to a tiered approach that provide more options with more granular control, as well as a top level "big hammer" option that cascades everywhere unless overridden by a more granular one (similar to the width heuristic options). For example, while some folks may want every brace to always be on its own line everywhere, others may indeed just want the style to apply to items and not say the bodies of their multiline match arms. This option as originally intended and implemented, controlling brace style for items, is actually probably a fair candidate for stabilization at this point, but if we need to extend it out to cover every expression context as well then it's likely to remain unstable for years to come. |
I think some of the confusion comes from the qualified naming of |
That sounds great.
I hope this does not mean that it cannot be renamed. |
Guess I'd missed this, but no, it has no impact. Even stabilized options can be renamed, provided we can do so without running into name conflicts with other options, as we can do such renames in a non-breaking manner. Obviously unstable options can be renamed or even removed as necessary. |
It would also be good to have a bit more specificity, for instance, be able to apply it only to certain types of elements and ignore others, for example: Goodpub struct Elevator { // Would be nice to have a way to ignore it applying to structs
projector: Projector,
height_map: GrayImage,
}
impl Elevator
{
pub fn new(radius: f64, origin: Coordinate, height_map: GrayImage) -> Self
{
Self {
height_map,
projector: Projector::new(radius, origin),
}
}
} Badpub struct Elevator
{
projector: Projector,
height_map: GrayImage,
}
impl Elevator
{
pub fn new(radius: f64, origin: Coordinate, height_map: GrayImage) -> Self
{
Self {
height_map,
projector: Projector::new(radius, origin),
}
}
} |
Is there a reason why RUST put's it's open bracket on the same line. Is it a performance thing? It's definitely not easier to read. Most languages place it on a new line, why change what works? I prefer the old method, unless someone knows why we shouldn't. |
It is just a matter of personal taste. Also I prefer it on a new line. Just seems the author of rustfmt probably prefers it differently. 4 years passed and this is still not resolved, still no progress? Other tools like for example linters even for javascript have options, but not rustfmt, this is what holds me back from using this otherwise seemingly great tool (for 4 years now). |
It appears it's probably not a very important feature for them if it's remained unstable for 4 years. I guess I'll just have to press the space bar one extra time, not a big deal. I'll pass on this until they decide to fix it. |
Hey all 👋🏼, just wanted to chime into the discussion with a little bit of info.
The default choice isn't based on any one persons opinion. rustfmt is primarily an implementation of the Rust Style Guide and the default formatting adheres to the guide. A lot of discussion has gone into it, and it's a living document that continues to evolve. These days, the guide is owned by the rust style team (check out the link for more details on the team). |
Ok so it is the opinion of some group of people. I think one of reasons is for crates to have consistent (the same) formatting and that is probably a good point. But this point should not apply to people using crates programming their projects, they can have their own style guides for their projects. |
Yes and no. Style decisions are made after coming to a consensus. Anyone is free to open PRs to discuss new default styles. And just to be clear, the style guide only prescribes the default style. I was simply trying to answer the earlier question and clarify that the rustfmt team isn't making style related decisions. |
I'm in the same situation I guess. This is one of the most basic formatting features, and it's still in unstable despite it already works well. Currently I made a workaround in my projects, a small shell script that switches to nightly, formats code, then switches backs to stable toolchain. How can I contribute to speed this up? |
I have no idea what you're talking about. Running a nightly The only issue with unstable options is that they are not guaranteed to achieve Rust's quality standard, and not guaranteed to never change formatting between toolchain releases. Neither are likely to be an issue for this specific feature. |
Tracking issue for unstable option: brace_style
The text was updated successfully, but these errors were encountered: