about summary refs log tree commit diff
path: root/src/docs/single_element_loop.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/docs/single_element_loop.txt')
-rw-r--r--src/docs/single_element_loop.txt21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/docs/single_element_loop.txt b/src/docs/single_element_loop.txt
new file mode 100644
index 00000000000..6f0c15a85f7
--- /dev/null
+++ b/src/docs/single_element_loop.txt
@@ -0,0 +1,21 @@
+### What it does
+Checks whether a for loop has a single element.
+
+### Why is this bad?
+There is no reason to have a loop of a
+single element.
+
+### Example
+```
+let item1 = 2;
+for item in &[item1] {
+    println!("{}", item);
+}
+```
+
+Use instead:
+```
+let item1 = 2;
+let item = &item1;
+println!("{}", item);
+```
\ No newline at end of file