-
Notifications
You must be signed in to change notification settings - Fork 932
Refactor chain formatting and fix some bugs #2838
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
Conversation
r? @topecongiro |
@topecongiro ping - will you get a chance to review this PR soon? If not, I'll merge and we can revisit later if necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies for the late review, I missed the first notification email. The code looks good to me. My only concern is the unindentation of the chain element that it is not orphaned, though if it is hard to fix right away, we can revisit this after merging this.
.map(|l| l.unwrap()) | ||
.enumerate(); | ||
.map(|l| l.unwrap()) | ||
.enumerate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure whether we should unindent when chain elements does not become orphaned.
src/chains.rs
Outdated
// foo.bar | ||
// .baz() | ||
// ``` | ||
// If `bar` were not part of the root, then baz would be orphaned and 'float'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshedding: in this case, the element that gets orphaned is foo
, not baz
:
foo
.bar
.baz()
Also we need a rebase. |
* More often combine a chain item to the previous line (if it is a block) * Don't indent if the parent is a block This is not perfect and doesn't pass tests, but I need to refactor to make more progress
Just refactoring, lots of code dup here, but it should get better...
And create `Chain` and `ChainItem` structs
pre-process the expression tree to get a list of chain items.
* remove unnecessary clone * comment formatting * fix bug with `?` collection * respect the heuristic if the root is more than just the parent
…ame line would introduce an open block or similar This problem came to light due to the chains changes, but effects other code too. It only happens rarely, e.g., before this fix: ``` match foo { MacroArgKind::Delimited(ref delim_tok, ref args) => rewrite_delimited_inner( delim_tok, args, ).map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs)), }; ``` after: ``` match foo { MacroArgKind::Delimited(ref delim_tok, ref args) => { rewrite_delimited_inner(delim_tok, args) .map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs)) } } ```
Closes rust-lang#2773 Closes rust-lang#2786
There's quite a lot of changes to formatting here. Most are net positive or neutral (IMO). There are a few changes to visual formatting that are not idea, but since that is not the default I think it is worth the price.