Skip to content

Commit 53f57b1

Browse files
committed
document that write!ing into a string never fails
1 parent 570dff6 commit 53f57b1

File tree

1 file changed

+6
-1
lines changed
  • clippy_lints/src/methods

1 file changed

+6
-1
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3385,7 +3385,12 @@ declare_clippy_lint! {
33853385
///
33863386
/// ### Why is this bad?
33873387
/// This allocates a new string for every element in the iterator.
3388-
/// This can be done more efficiently by creating the `String` once and appending to it using `Iterator::fold`.
3388+
/// This can be done more efficiently by creating the `String` once and appending to it in `Iterator::fold`,
3389+
/// using either the `write!` macro which supports exactly the same syntax as the `format!` macro,
3390+
/// or concatenating with `+` in case the iterator yields `&str`/`String`.
3391+
///
3392+
/// Note also that `write!`-ing into a `String` can never fail, despite the return type of `write!` being `std::fmt::Result`,
3393+
/// so it can be safely ignored or unwrapped.
33893394
///
33903395
/// ### Example
33913396
/// ```rust

0 commit comments

Comments
 (0)