rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Formatting of consecutive vec! lines requires multiple runs

Open wichert opened this issue 1 year ago • 1 comments

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.

wichert avatar Jul 02 '24 11:07 wichert

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

ytmimi avatar Jul 02 '24 14:07 ytmimi