Skip to content

seek_to_start_instead_of_rewind fires when rewind cannot replace seek #10065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
poliorcetics opened this issue Dec 12, 2022 · 0 comments · Fixed by #10096
Closed

seek_to_start_instead_of_rewind fires when rewind cannot replace seek #10065

poliorcetics opened this issue Dec 12, 2022 · 0 comments · Fixed by #10096
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@poliorcetics
Copy link

poliorcetics commented Dec 12, 2022

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

@poliorcetics poliorcetics added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 12, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Dec 12, 2022
@bors bors closed this as completed in 391b2a6 Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants