mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Add msrv check for rewind_instead_of_seek_to_start
lint
Signed-off-by: Doru-Florin Blanzeanu <blanzeanu.doru@protonmail.com>
This commit is contained in:
parent
8d6ce3177b
commit
b48a4668f4
5 changed files with 99 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue