diff options
Diffstat (limited to '')
-rw-r--r-- | src/tools/clippy/src/docs/len_without_is_empty.txt | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/len_without_is_empty.txt b/src/tools/clippy/src/docs/len_without_is_empty.txt new file mode 100644 index 000000000..47a2e8575 --- /dev/null +++ b/src/tools/clippy/src/docs/len_without_is_empty.txt @@ -0,0 +1,19 @@ +### What it does +Checks for items that implement `.len()` but not +`.is_empty()`. + +### Why is this bad? +It is good custom to have both methods, because for +some data structures, asking about the length will be a costly operation, +whereas `.is_empty()` can usually answer in constant time. Also it used to +lead to false positives on the [`len_zero`](#len_zero) lint – currently that +lint will ignore such entities. + +### Example +``` +impl X { + pub fn len(&self) -> usize { + .. + } +} +```
\ No newline at end of file |