diff options
Diffstat (limited to 'src/tools/clippy/src/docs/inherent_to_string.txt')
-rw-r--r-- | src/tools/clippy/src/docs/inherent_to_string.txt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/inherent_to_string.txt b/src/tools/clippy/src/docs/inherent_to_string.txt new file mode 100644 index 000000000..b18e600e9 --- /dev/null +++ b/src/tools/clippy/src/docs/inherent_to_string.txt @@ -0,0 +1,29 @@ +### What it does +Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`. + +### Why is this bad? +This method is also implicitly defined if a type implements the `Display` trait. As the functionality of `Display` is much more versatile, it should be preferred. + +### Example +``` +pub struct A; + +impl A { + pub fn to_string(&self) -> String { + "I am A".to_string() + } +} +``` + +Use instead: +``` +use std::fmt; + +pub struct A; + +impl fmt::Display for A { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "I am A") + } +} +```
\ No newline at end of file |