Skip to content

New lint: Suggest stream_position for self.seek(SeekFrom::Current(0)) #7886

Closed
@crumblingstatue

Description

@crumblingstatue

What it does

Suggests to use stream_position() over seek(SeekFrom::Current(0)).

Categories (optional)

  • Kind: clippy::style

Since Rust 1.51, the Seek trait has a stream_position method.
Using it makes the intent more clear over seek.

Drawbacks

None.

Example

use std::fs::File;
use std::io::{self, Write, Seek, SeekFrom};

fn main() -> io::Result<()> {
    let mut f = File::create("foo.txt")?;
    f.write_all(b"Hi!")?;
    eprintln!("Written {} bytes.", f.seek(SeekFrom::Current(0))?);
    Ok(())
}

Could be written as:

use std::fs::File;
use std::io::{self, Write, Seek};

fn main() -> io::Result<()> {
    let mut f = File::create("foo.txt")?;
    f.write_all(b"Hi!")?;
    eprintln!("Written {} bytes.", f.stream_position()?);
    Ok(())
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions