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

Formatting of consecutive vec! lines requires multiple runs #6227

Open
wichert opened this issue Jul 2, 2024 · 1 comment
Open

Formatting of consecutive vec! lines requires multiple runs #6227

wichert opened this issue Jul 2, 2024 · 1 comment
Labels
a-macros bug Panic, non-idempotency, invalid code, etc. poor-formatting

Comments

@wichert
Copy link

wichert commented Jul 2, 2024

rustfmt requires multiple runs to generate consistent output for this input code:

fn zserio_read(&mut self, reader: &mut BitReader) -> Result<()> {
    self.headers = vec![crate::reference_modules::parameter_passing::index_operator::block_header::BlockHeader::new(); headers_array_length];
    self.blocks = vec![crate::reference_modules::parameter_passing::index_operator::block::Block::new(); blocks_array_length];
}

After a first pass the code is updated to this:

fn zserio_read(&mut self, reader: &mut BitReader) -> Result<()> {
    self.headers = vec![crate::reference_modules::parameter_passing::index_operator::block_header::BlockHeader::new(); headers_array_length];
    self.blocks =
        vec![
            crate::reference_modules::parameter_passing::index_operator::block::Block::new();
            blocks_array_length
        ];
}

And after a second pass it moves the vec! invocation to the line with the assignment:

fn zserio_read(&mut self, reader: &mut BitReader) -> Result<()> {
    self.headers = vec![crate::reference_modules::parameter_passing::index_operator::block_header::BlockHeader::new(); headers_array_length];
    self.blocks = vec![
            crate::reference_modules::parameter_passing::index_operator::block::Block::new();
            blocks_array_length
        ];
}

after this rustfmt is happy an running it again creates no further changes.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 2, 2024

Thanks for the report. The indentation on the second vec![] looks off to me too.

@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. poor-formatting a-macros labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-macros bug Panic, non-idempotency, invalid code, etc. poor-formatting
Projects
None yet
Development

No branches or pull requests

2 participants