Skip to main content

Lint clippy::format_collect

warning clippy::format_collect §

use of `format!` to build up a string from an iterator

src/render/suggestions.rs:324:22

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • cargo-clippy-html (bin)

Primary: src/render/suggestions.rs:324:22

        let before = (0..30).map(|i| format!("line{i}\n")).collect::<String>();

Primary: src/render/suggestions.rs:324:30

        let before = (0..30).map(|i| format!("line{i}\n")).collect::<String>();

Primary: src/render/suggestions.rs:324:38

        let before = (0..30).map(|i| format!("line{i}\n")).collect::<String>();

help: call `fold` instead

help: ... and use the `write!` macro here

note: this can be written more efficiently by appending to a `String` directly

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#format_collect

note: `-W clippy::format-collect` implied by `-W clippy::pedantic`

help: to override `-W clippy::pedantic` add `#[allow(clippy::format_collect)]`

Rendered diagnostic (text)
warning: use of `format!` to build up a string from an iterator
   --> src/render/suggestions.rs:324:22
    |
324 |         let before = (0..30).map(|i| format!("line{i}\n")).collect::<String>();
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
help: call `fold` instead
   --> src/render/suggestions.rs:324:30
    |
324 |         let before = (0..30).map(|i| format!("line{i}\n")).collect::<String>();
    |                              ^^^
help: ... and use the `write!` macro here
   --> src/render/suggestions.rs:324:38
    |
324 |         let before = (0..30).map(|i| format!("line{i}\n")).collect::<String>();
    |                                      ^^^^^^^^^^^^^^^^^^^^
    = note: this can be written more efficiently by appending to a `String` directly
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#format_collect
    = note: `-W clippy::format-collect` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::format_collect)]`