Skip to content

Commit b48a466

Browse files
committed
Add msrv check for rewind_instead_of_seek_to_start lint
Signed-off-by: Doru-Florin Blanzeanu <[email protected]>
1 parent 8d6ce31 commit b48a466

File tree

5 files changed

+99
-4
lines changed

5 files changed

+99
-4
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3638,7 +3638,9 @@ impl Methods {
36383638
vec_resize_to_zero::check(cx, expr, count_arg, default_arg, span);
36393639
},
36403640
("seek", [arg]) => {
3641-
rewind_instead_of_seek_to_start::check(cx, expr, recv, arg, span);
3641+
if meets_msrv(self.msrv, msrvs::SEEK_REWIND) {
3642+
rewind_instead_of_seek_to_start::check(cx, expr, recv, arg, span);
3643+
}
36423644
},
36433645
("sort", []) => {
36443646
stable_sort_primitive::check(cx, expr, recv);

clippy_utils/src/msrvs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ msrv_aliases! {
3737
1,18,0 { HASH_MAP_RETAIN, HASH_SET_RETAIN }
3838
1,17,0 { FIELD_INIT_SHORTHAND, STATIC_IN_CONST, EXPECT_ERR }
3939
1,16,0 { STR_REPEAT }
40+
1,55,0 { SEEK_REWIND }
4041
}

tests/ui/rewind_instead_of_seek_to_start.fixed

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22
#![allow(unused)]
3+
#![feature(custom_inner_attributes)]
34
#![warn(clippy::rewind_instead_of_seek_to_start)]
45

56
use std::fs::OpenOptions;
@@ -92,3 +93,45 @@ fn main() {
9293

9394
assert_eq!(&buf, hello);
9495
}
96+
97+
fn msrv_1_54() {
98+
#![clippy::msrv = "1.54"]
99+
100+
let mut f = OpenOptions::new()
101+
.write(true)
102+
.read(true)
103+
.create(true)
104+
.open("foo.txt")
105+
.unwrap();
106+
107+
let hello = "Hello!\n";
108+
write!(f, "{hello}").unwrap();
109+
110+
f.seek(SeekFrom::Start(0));
111+
112+
let mut buf = String::new();
113+
f.read_to_string(&mut buf).unwrap();
114+
115+
assert_eq!(&buf, hello);
116+
}
117+
118+
fn msrv_1_55() {
119+
#![clippy::msrv = "1.55"]
120+
121+
let mut f = OpenOptions::new()
122+
.write(true)
123+
.read(true)
124+
.create(true)
125+
.open("foo.txt")
126+
.unwrap();
127+
128+
let hello = "Hello!\n";
129+
write!(f, "{hello}").unwrap();
130+
131+
f.rewind();
132+
133+
let mut buf = String::new();
134+
f.read_to_string(&mut buf).unwrap();
135+
136+
assert_eq!(&buf, hello);
137+
}

tests/ui/rewind_instead_of_seek_to_start.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22
#![allow(unused)]
3+
#![feature(custom_inner_attributes)]
34
#![warn(clippy::rewind_instead_of_seek_to_start)]
45

56
use std::fs::OpenOptions;
@@ -92,3 +93,45 @@ fn main() {
9293

9394
assert_eq!(&buf, hello);
9495
}
96+
97+
fn msrv_1_54() {
98+
#![clippy::msrv = "1.54"]
99+
100+
let mut f = OpenOptions::new()
101+
.write(true)
102+
.read(true)
103+
.create(true)
104+
.open("foo.txt")
105+
.unwrap();
106+
107+
let hello = "Hello!\n";
108+
write!(f, "{hello}").unwrap();
109+
110+
f.seek(SeekFrom::Start(0));
111+
112+
let mut buf = String::new();
113+
f.read_to_string(&mut buf).unwrap();
114+
115+
assert_eq!(&buf, hello);
116+
}
117+
118+
fn msrv_1_55() {
119+
#![clippy::msrv = "1.55"]
120+
121+
let mut f = OpenOptions::new()
122+
.write(true)
123+
.read(true)
124+
.create(true)
125+
.open("foo.txt")
126+
.unwrap();
127+
128+
let hello = "Hello!\n";
129+
write!(f, "{hello}").unwrap();
130+
131+
f.seek(SeekFrom::Start(0));
132+
133+
let mut buf = String::new();
134+
f.read_to_string(&mut buf).unwrap();
135+
136+
assert_eq!(&buf, hello);
137+
}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
error: used `seek` to go to the start of the stream
2-
--> $DIR/rewind_instead_of_seek_to_start.rs:53:7
2+
--> $DIR/rewind_instead_of_seek_to_start.rs:54:7
33
|
44
LL | t.seek(SeekFrom::Start(0));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
66
|
77
= note: `-D clippy::rewind-instead-of-seek-to-start` implied by `-D warnings`
88

99
error: used `seek` to go to the start of the stream
10-
--> $DIR/rewind_instead_of_seek_to_start.rs:58:7
10+
--> $DIR/rewind_instead_of_seek_to_start.rs:59:7
1111
|
1212
LL | t.seek(SeekFrom::Start(0));
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
1414

15-
error: aborting due to 2 previous errors
15+
error: used `seek` to go to the start of the stream
16+
--> $DIR/rewind_instead_of_seek_to_start.rs:131:7
17+
|
18+
LL | f.seek(SeekFrom::Start(0));
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
20+
21+
error: aborting due to 3 previous errors
1622

0 commit comments

Comments
 (0)