diff options
| author | Doru-Florin Blanzeanu <blanzeanu.doru@protonmail.com> | 2022-10-21 16:08:04 +0000 |
|---|---|---|
| committer | Doru-Florin Blanzeanu <blanzeanu.doru@protonmail.com> | 2022-10-24 11:00:56 +0000 |
| commit | b48a4668f4767412b3d9797ce3d6ee63f351caee (patch) | |
| tree | b245104639bc870ee810c15d80c2d5fd9bd2b81d | |
| parent | 8d6ce3177bd5d4d05723dec1cdd869effc926fc3 (diff) | |
| download | rust-b48a4668f4767412b3d9797ce3d6ee63f351caee.tar.gz rust-b48a4668f4767412b3d9797ce3d6ee63f351caee.zip | |
Add msrv check for `rewind_instead_of_seek_to_start` lint
Signed-off-by: Doru-Florin Blanzeanu <blanzeanu.doru@protonmail.com>
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 4 | ||||
| -rw-r--r-- | clippy_utils/src/msrvs.rs | 1 | ||||
| -rw-r--r-- | tests/ui/rewind_instead_of_seek_to_start.fixed | 43 | ||||
| -rw-r--r-- | tests/ui/rewind_instead_of_seek_to_start.rs | 43 | ||||
| -rw-r--r-- | tests/ui/rewind_instead_of_seek_to_start.stderr | 12 |
5 files changed, 99 insertions, 4 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e794af7d64b..7b0a676e89e 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3638,7 +3638,9 @@ impl Methods { vec_resize_to_zero::check(cx, expr, count_arg, default_arg, span); }, ("seek", [arg]) => { - rewind_instead_of_seek_to_start::check(cx, expr, recv, arg, span); + if meets_msrv(self.msrv, msrvs::SEEK_REWIND) { + rewind_instead_of_seek_to_start::check(cx, expr, recv, arg, span); + } }, ("sort", []) => { stable_sort_primitive::check(cx, expr, recv); diff --git a/clippy_utils/src/msrvs.rs b/clippy_utils/src/msrvs.rs index 8b843732a23..6f77155ec3e 100644 --- a/clippy_utils/src/msrvs.rs +++ b/clippy_utils/src/msrvs.rs @@ -37,4 +37,5 @@ msrv_aliases! { 1,18,0 { HASH_MAP_RETAIN, HASH_SET_RETAIN } 1,17,0 { FIELD_INIT_SHORTHAND, STATIC_IN_CONST, EXPECT_ERR } 1,16,0 { STR_REPEAT } + 1,55,0 { SEEK_REWIND } } diff --git a/tests/ui/rewind_instead_of_seek_to_start.fixed b/tests/ui/rewind_instead_of_seek_to_start.fixed index 037a288b69b..36853780977 100644 --- a/tests/ui/rewind_instead_of_seek_to_start.fixed +++ b/tests/ui/rewind_instead_of_seek_to_start.fixed @@ -1,5 +1,6 @@ // run-rustfix #![allow(unused)] +#![feature(custom_inner_attributes)] #![warn(clippy::rewind_instead_of_seek_to_start)] use std::fs::OpenOptions; @@ -92,3 +93,45 @@ fn main() { assert_eq!(&buf, hello); } + +fn msrv_1_54() { + #![clippy::msrv = "1.54"] + + let mut f = OpenOptions::new() + .write(true) + .read(true) + .create(true) + .open("foo.txt") + .unwrap(); + + let hello = "Hello!\n"; + write!(f, "{hello}").unwrap(); + + f.seek(SeekFrom::Start(0)); + + let mut buf = String::new(); + f.read_to_string(&mut buf).unwrap(); + + assert_eq!(&buf, hello); +} + +fn msrv_1_55() { + #![clippy::msrv = "1.55"] + + let mut f = OpenOptions::new() + .write(true) + .read(true) + .create(true) + .open("foo.txt") + .unwrap(); + + let hello = "Hello!\n"; + write!(f, "{hello}").unwrap(); + + f.rewind(); + + let mut buf = String::new(); + f.read_to_string(&mut buf).unwrap(); + + assert_eq!(&buf, hello); +} diff --git a/tests/ui/rewind_instead_of_seek_to_start.rs b/tests/ui/rewind_instead_of_seek_to_start.rs index 2622425128d..0d061b58fba 100644 --- a/tests/ui/rewind_instead_of_seek_to_start.rs +++ b/tests/ui/rewind_instead_of_seek_to_start.rs @@ -1,5 +1,6 @@ // run-rustfix #![allow(unused)] +#![feature(custom_inner_attributes)] #![warn(clippy::rewind_instead_of_seek_to_start)] use std::fs::OpenOptions; @@ -92,3 +93,45 @@ fn main() { assert_eq!(&buf, hello); } + +fn msrv_1_54() { + #![clippy::msrv = "1.54"] + + let mut f = OpenOptions::new() + .write(true) + .read(true) + .create(true) + .open("foo.txt") + .unwrap(); + + let hello = "Hello!\n"; + write!(f, "{hello}").unwrap(); + + f.seek(SeekFrom::Start(0)); + + let mut buf = String::new(); + f.read_to_string(&mut buf).unwrap(); + + assert_eq!(&buf, hello); +} + +fn msrv_1_55() { + #![clippy::msrv = "1.55"] + + let mut f = OpenOptions::new() + .write(true) + .read(true) + .create(true) + .open("foo.txt") + .unwrap(); + + let hello = "Hello!\n"; + write!(f, "{hello}").unwrap(); + + f.seek(SeekFrom::Start(0)); + + let mut buf = String::new(); + f.read_to_string(&mut buf).unwrap(); + + assert_eq!(&buf, hello); +} diff --git a/tests/ui/rewind_instead_of_seek_to_start.stderr b/tests/ui/rewind_instead_of_seek_to_start.stderr index f985471ac05..e8086781084 100644 --- a/tests/ui/rewind_instead_of_seek_to_start.stderr +++ b/tests/ui/rewind_instead_of_seek_to_start.stderr @@ -1,5 +1,5 @@ error: used `seek` to go to the start of the stream - --> $DIR/rewind_instead_of_seek_to_start.rs:53:7 + --> $DIR/rewind_instead_of_seek_to_start.rs:54:7 | LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` @@ -7,10 +7,16 @@ LL | t.seek(SeekFrom::Start(0)); = note: `-D clippy::rewind-instead-of-seek-to-start` implied by `-D warnings` error: used `seek` to go to the start of the stream - --> $DIR/rewind_instead_of_seek_to_start.rs:58:7 + --> $DIR/rewind_instead_of_seek_to_start.rs:59:7 | LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` -error: aborting due to 2 previous errors +error: used `seek` to go to the start of the stream + --> $DIR/rewind_instead_of_seek_to_start.rs:131:7 + | +LL | f.seek(SeekFrom::Start(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` + +error: aborting due to 3 previous errors |
