Skip to content

Change rewrite return type from Option to Return #3420

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

Open
scampi opened this issue Feb 27, 2019 · 1 comment
Open

Change rewrite return type from Option to Return #3420

scampi opened this issue Feb 27, 2019 · 1 comment
Labels

Comments

@scampi
Copy link
Contributor

scampi commented Feb 27, 2019

In issues #3206 #3416 #3135, wrap_str is preventing some possibly good formatting because of long strings. The return type being an Option, the fact that the rewrite failed because of a long string is lost.
If that were returning a Return, then the failure reason could be passed up for the callee to handle as appropriate.

For example, it seems the rewrite in #3416 could allow the line to overflow (which anyway would be caught by the LineOverflow logic). However, there are cases where a better formatting is possible, e.g.:

// original
fn foo() {
    let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx
        .map(|x| x + 5)
        .map(|x| x / 2)
        .fold(0, |acc, x| acc + x);
}

// formatted
fn foo() {
     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
         xxxxxxx.map(|x| x + 5)
                .map(|x| x / 2)
                .fold(0, |acc, x| acc + x);
}

Although in that example there is no long string, the current wrap_str logic makes that formatting possible.

With a Return as the return type, rewrite methods could be made more flexible to various kinds of errors.
However, that change would require some heavy refactoring I think.

What do you think about such a change ?

@topecongiro topecongiro added the fun! :) label Mar 5, 2019
@scampi
Copy link
Contributor Author

scampi commented May 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants