Files
rust/tests/ui/recursive_format_impl.stderr
T
Yuri Astrakhan aaa5bd244e Add useless_borrows_in_formatting lint
Detect format macros where an argument
is passed with an explicit `&` even though the formatter already takes
references, e.g. `println!("{}", &s)` when `s: &str`.

Some original micro-benchmarks showed ~6% performance improvement when redundant refs are removed.

- Lint runs for both Display (`{}`) and Debug (`{:?}`) placeholders when
  the inner type is Sized and implements the corresponding trait.
- Applies to the main value argument and to width/precision arguments
  (e.g. `format!("{0:1$.2$}", &v1, &v2, &v3)`).
- Suggests removing the redundant `&` with MachineApplicable fix.
- Skip when the argument comes from expansion or a proc macro.
2026-04-17 11:04:55 -04:00

66 lines
2.3 KiB
Plaintext

error: using `self.to_string` in `fmt::Display` implementation will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:32:25
|
LL | write!(f, "{}", self.to_string())
| ^^^^^^^^^^^^^^^^
|
= note: `-D clippy::recursive-format-impl` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::recursive_format_impl)]`
error: using `self` as `Display` in `impl Display` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:77:9
|
LL | write!(f, "{}", self)
| ^^^^^^^^^^^^^^^^^^^^^
error: using `self` as `Display` in `impl Display` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:87:9
|
LL | write!(f, "{}", &self)
| ^^^^^^^^^^^^^^^^^^^^^^
error: using `self` as `Debug` in `impl Debug` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:94:9
|
LL | write!(f, "{:?}", &self)
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: using `self` as `Display` in `impl Display` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:104:9
|
LL | write!(f, "{}", &&&self)
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: using `self` as `Display` in `impl Display` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:179:9
|
LL | write!(f, "{}", &*self)
| ^^^^^^^^^^^^^^^^^^^^^^^
error: using `self` as `Debug` in `impl Debug` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:186:9
|
LL | write!(f, "{:?}", &*self)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: using `self` as `Display` in `impl Display` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:203:9
|
LL | write!(f, "{}", *self)
| ^^^^^^^^^^^^^^^^^^^^^^
error: using `self` as `Display` in `impl Display` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:220:9
|
LL | write!(f, "{}", **&&*self)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: using `self` as `Display` in `impl Display` will cause infinite recursion
--> tests/ui/recursive_format_impl.rs:237:9
|
LL | write!(f, "{}", &&**&&*self)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 10 previous errors