Skip to content

Formatting of consecutive vec! lines requires multiple runs #6227

Open
@wichert

Description

@wichert

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions