Skip to content

seek_to_start_instead_of_rewind fires when rewind cannot replace seek #10065

Closed
@poliorcetics

Description

@poliorcetics

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions