-
Notifications
You must be signed in to change notification settings - Fork 871
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] spaces_around_ranges #3367
Comments
I'm not sure if this is the correct place for feedback, but I wish there was more distinction that just a boolean. |
@msrd0 - this is indeed a great place to ask questions/make suggestions about the type of a config option, associated variants, etc. so thanks for sharing. Do you think it's more about there being a space, or is it perhaps specifically when the lhs and/or rhs of the range expression are themselves binary expressions? I'd be open to evolving the current config option to have a variant for adding spaces in the presence of some form of "complexity", but I feel like a whitespace-driven determination would be a bit too blunt of an approach |
I wouldn't necessarily limit this to binary expressions, I'd prefer something like |
We already do formatting consideration of spaces based on the kinds of expressions (since a float expression on the lhs or a nested range on the rhs could be botched without spaces), so it would certainly be feasible to add a variant that would always add a space unless both the lhs and rhs kinds were either a lit or path. However, I do want to be mindful about the potential for this to snowball to account for all sorts of expression kind combinations because there's quite a lot of them. |
There are, yes. My personal feeling is that "spaces should align with operator precedence", hence:
|
I also feel that whitespace-driven rules are a bit blunt. My mental model is that spaces should be inserted if there is some extra computation that needs to happen before the range can be evaluated. Computation only needs to happen on one side of the range for spaces to be inserted on both sides. So if we are only looking at values that need to be retrieved (whether they are struct fields, values from modules (ex. There are a couple of awkward situations where rustfmt wouldn't be able to do the correct thing because it doesn't have access to the right information in the AST (I think?). For example, a function like |
Tracking issue for unstable option: spaces_around_ranges
The text was updated successfully, but these errors were encountered: