Skip to content

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

Merged
merged 19 commits into from
Jul 24, 2018
Merged

Refactor chain formatting and fix some bugs #2838

merged 19 commits into from
Jul 24, 2018

Conversation

nrc
Copy link
Member

@nrc nrc commented Jul 12, 2018

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.

@nrc
Copy link
Member Author

nrc commented Jul 12, 2018

r? @topecongiro

@nrc
Copy link
Member Author

nrc commented Jul 22, 2018

@topecongiro ping - will you get a chance to review this PR soon? If not, I'll merge and we can revisit later if necessary.

Copy link
Contributor

@topecongiro topecongiro left a 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();
Copy link
Contributor

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'.
Copy link
Contributor

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()

@topecongiro
Copy link
Contributor

Also we need a rebase.

nrc added 19 commits July 24, 2018 15:43
* 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))
        }
    }

```
@nrc nrc merged commit a24df13 into rust-lang:master Jul 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants