Skip to content
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

Poor formatting of let foo = { bar } #3419

Closed
ghost opened this issue Feb 26, 2019 · 1 comment · Fixed by #4016
Closed

Poor formatting of let foo = { bar } #3419

ghost opened this issue Feb 26, 2019 · 1 comment · Fixed by #4016
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-macros poor-formatting

Comments

@ghost
Copy link

ghost commented Feb 26, 2019

The following code:

lazy_static! {
    pub static ref BLOCKING_POOL: tokio_threadpool::ThreadPool = {
        tokio_threadpool::Builder::new().pool_size(1).build()
    };

    static ref FOO: Foo = unsafe {
        very_long_function_name().another_function_with_really_long_name()
    };
}

Gets formatted as:

lazy_static! {
    pub static ref BLOCKING_POOL: tokio_threadpool::ThreadPool =
        { tokio_threadpool::Builder::new().pool_size(1).build() };
    static ref FOO: Foo =
        unsafe { extremely_long_function_name().another_function_with_long_name() };
}

Which is much less readable to me. First, the blank line is deleted, and second, { very_long_expression } on a dedicated line doesn't look great. I think we should never break = { or = unsafe { into two lines.

@ghost
Copy link
Author

ghost commented Feb 27, 2019

What is even more strange is, if we add a blank comment in between the declarations, then rustfmt does nothing!

lazy_static! {
    pub static ref BLOCKING_POOL: tokio_threadpool::ThreadPool = { tokio_threadpool::Builder::new().pool_size(1).build() };

    //

    static ref FOO: Foo = unsafe { very_long_function_name().another_function_with_really_long_name() };
}

This looks like a bug.

@calebcartwright calebcartwright added the 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release label Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-macros poor-formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants