diff options
Diffstat (limited to 'src/docs/recursive_format_impl.txt')
| -rw-r--r-- | src/docs/recursive_format_impl.txt | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/src/docs/recursive_format_impl.txt b/src/docs/recursive_format_impl.txt deleted file mode 100644 index 32fffd84cf4..00000000000 --- a/src/docs/recursive_format_impl.txt +++ /dev/null @@ -1,32 +0,0 @@ -### What it does -Checks for format trait implementations (e.g. `Display`) with a recursive call to itself -which uses `self` as a parameter. -This is typically done indirectly with the `write!` macro or with `to_string()`. - -### Why is this bad? -This will lead to infinite recursion and a stack overflow. - -### Example - -``` -use std::fmt; - -struct Structure(i32); -impl fmt::Display for Structure { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.to_string()) - } -} - -``` -Use instead: -``` -use std::fmt; - -struct Structure(i32); -impl fmt::Display for Structure { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } -} -``` \ No newline at end of file |
