Clippy lints / Complexity
Clippy lint · Complexity · checked with Clippy 0.1.99
clippy::seek_to_start_instead_of_rewind: Checks for jumps to the start of a stream that implements Seek and uses the seek method providing Start as parameter
What it meansChecks for jumps to the start of a stream that implements Seek and uses the seek method providing Start as parameter. It is in the complexity group and warns by default.
Does it matter?
Readability. There is a specific method that was implemented for this exact scenario.
Code that does something simple in a complicated way. Warns by default.
How to fix it
Clippy can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
fn foo<T: io::Seek>(t: &mut T) {
t.seek(io::SeekFrom::Start(0));
}
Write this instead
fn foo<T: io::Seek>(t: &mut T) {
t.rewind();
}
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::seek_to_start_instead_of_rewind)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
seek_to_start_instead_of_rewind = "allow"One run
cargo clippy -- -A clippy::seek-to-start-instead-of-rewindThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for jumps to the start of a stream that implements Seek
and uses the seek method providing Start as parameter.
Why is this bad?
Readability. There is a specific method that was implemented for this exact scenario.
Example
fn foo<T: io::Seek>(t: &mut T) {
t.seek(io::SeekFrom::Start(0));
}
Use instead:
fn foo<T: io::Seek>(t: &mut T) {
t.rewind();
}
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- too_many_argumentsChecks for functions with too many parameters
- clone_on_copyusing `clone` on type `u64` which implements the `Copy` trait
- type_complexityChecks for types used in structs, parameters and let declarations above a certain complexity threshold
- result_filter_map`filter` for `Ok` followed by `unwrap`
- result_map_unit_fnChecks for usage of result.map(f) where f is a function or closure that returns the unit type ()
- seek_from_currentusing `SeekFrom::Current` to start from current position
- short_circuit_statementChecks for the use of short circuit boolean conditions as a statement
- single_element_loopfor loop over a single element
- skip_while_nextChecks for usage of _.skip_while(condition).next()
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::too_many_argumentsChecks for functions with too many parametersRead it next →Did this answer your question?