Skip to content

Formatting of consecutive vec! lines requires multiple runs #6227

@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

    A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-poor-formattingIssue: poor formatting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions