rust-clippy/tests/ui/to_string_in_display.rs

70 lines
1.1 KiB
Rust
Raw Normal View History

2020-07-22 12:44:53 +00:00
#![warn(clippy::to_string_in_display)]
2021-09-30 11:40:46 +00:00
#![allow(clippy::inherent_to_string_shadow_display, clippy::to_string_in_format_args)]
2020-07-22 12:44:53 +00:00
use std::fmt;
struct A;
impl A {
fn fmt(&self) {
self.to_string();
}
}
trait B {
fn fmt(&self) {}
}
impl B for A {
fn fmt(&self) {
self.to_string();
}
}
impl fmt::Display for A {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
}
}
fn fmt(a: A) {
a.to_string();
}
struct C;
impl C {
fn to_string(&self) -> String {
String::from("I am C")
}
}
impl fmt::Display for C {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
}
}
enum D {
E(String),
F,
}
impl std::fmt::Display for D {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self {
Self::E(string) => write!(f, "E {}", string.to_string()),
Self::F => write!(f, "F"),
}
}
}
2020-07-22 12:44:53 +00:00
fn main() {
let a = A;
a.to_string();
a.fmt();
fmt(a);
let c = C;
c.to_string();
}