about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDoru-Florin Blanzeanu <blanzeanu.doru@protonmail.com>2022-10-16 19:31:03 +0000
committerDoru-Florin Blanzeanu <blanzeanu.doru@protonmail.com>2022-10-24 10:43:48 +0000
commit8d6ce3177bd5d4d05723dec1cdd869effc926fc3 (patch)
tree697ae96dd3b5c5de362dcf0b6c60b2823cb2d848 /src
parent5b09d4e1f7082aff024faf27263f78e7fc7190a2 (diff)
downloadrust-8d6ce3177bd5d4d05723dec1cdd869effc926fc3.tar.gz
rust-8d6ce3177bd5d4d05723dec1cdd869effc926fc3.zip
Add new lint `rewind_instead_of_seek_to_start`
Signed-off-by: Doru-Florin Blanzeanu <blanzeanu.doru@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/docs/rewind_instead_of_seek_to_start.txt22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/docs/rewind_instead_of_seek_to_start.txt b/src/docs/rewind_instead_of_seek_to_start.txt
new file mode 100644
index 00000000000..bef11b2312a
--- /dev/null
+++ b/src/docs/rewind_instead_of_seek_to_start.txt
@@ -0,0 +1,22 @@
+### What it does
+
+Checks for jumps to the start of a stream that implements `Seek`
+and uses the `seek` method providing `Start` as parameter.
+
+### Why is this bad?
+
+Readability. There is a specific method that was implemented for
+this exact scenario.
+
+### Example
+```
+fn foo<T: io::Seek>(t: &mut T) {
+    t.seek(io::SeekFrom::Start(0));
+}
+```
+Use instead:
+```
+fn foo<T: io::Seek>(t: &mut T) {
+    t.rewind();
+}
+```
\ No newline at end of file