Closed
Description
Summary
seek_to_start_instead_of_rewind
fires when rewind
cannot replace seek
because rewind
returns std::io::Result<()>
and seek
returns std::io::Result<u64>
.
Lint Name
seek_to_start_instead_of_rewind
Reproducer
I tried this code:
use std::io::{Seek, SeekFrom};
use std::fs::File;
fn main() {
let mut f = File::open("some-file.txt").unwrap();
// ... cut ...
let old_offset = f.seek(SeekFrom::Start(0)).unwrap();
// do some operation from start of file and
// restore file pointer to where we found it
f.seek(SeekFrom::Start(old_offset)).unwrap();
// ...
}
I saw this happen:
warning: used `seek` to go to the start of the stream
--> src/main.rs:7:24
|
7 | let old_offset = f.seek(SeekFrom::Start(0)).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#seek_to_start_instead_of_rewind
= note: `#[warn(clippy::seek_to_start_instead_of_rewind)]` on by default
I expected to see this happen:
Not linting because rewind
returns a ()
whereas seek
returns the old position, they're not interchangeable in case of assignement.
Version
rustc 1.68.0-nightly (bdb07a8ec 2022-12-11)
binary: rustc
commit-hash: bdb07a8ec8e77aa10fb84fae1d4ff71c21180bb4
commit-date: 2022-12-11
host: aarch64-apple-darwin
release: 1.68.0-nightly
LLVM version: 15.0.6
Additional Labels
@rustbot label +I-suggestion-causes-error