diff options
| author | Philipp Krones <hello@philkrones.com> | 2022-11-21 19:59:07 +0100 |
|---|---|---|
| committer | Philipp Krones <hello@philkrones.com> | 2022-11-21 20:01:17 +0100 |
| commit | fd5b85c957d92a3bc5fc754407d1e56aa9178d27 (patch) | |
| tree | cba25a7cb16b8f5981eb75b1138ece61bb412fb6 /src/docs/recursive_format_impl.txt | |
| parent | 80a4699aaeb17903cd55c3159764febf3ff4e7e9 (diff) | |
| parent | 51ec465cc3dfb62a2dad7e808b399fa76a1c9170 (diff) | |
Merge remote-tracking branch 'upstream/master' into rustup
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 |
