Clippy lints / Correctness
Clippy lint · Correctness · checked with Clippy 0.1.99
clippy::suspicious_splitn: Checks for calls to [splitn] (https://doc.rust-lang.org/std/primitive.str.html#method.splitn) and related functions with either zero or one splits
What it meansChecks for calls to [splitn] (https://doc.rust-lang.org/std/primitive.str.html#method.splitn) and related functions with either zero or one splits. It is in the correctness group and denied by default (the build fails).
Does it matter?
These calls don’t actually split the value and are likely to be intended as a different number.
Code that is almost certainly wrong. Denied by default: the build fails until you fix it or allow it.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
for x in s.splitn(1, ":") {
// ..
}
Write this instead
for x in s.splitn(2, ":") {
// ..
}
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::suspicious_splitn)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
suspicious_splitn = "allow"One run
cargo clippy -- -A clippy::suspicious-splitnThe [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 calls to [splitn]
(https://doc.rust-lang.org/std/primitive.str.html#method.splitn) and
related functions with either zero or one splits.
Why is this bad?
These calls don’t actually split the value and are likely to be intended as a different number.
Example
for x in s.splitn(1, ":") {
// ..
}
Use instead:
for x in s.splitn(2, ":") {
// ..
}
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- self_assignmentself-assignment of `a.x` to `a.x`
- serde_api_misuseChecks for misuses of the serde API
- size_of_in_element_countDetects expressions where size_of::<T> or size_of_val::<T> is used as a count of elements of type T
- transmute_null_to_fntransmuting a known null pointer into a function pointer
- transmuting_nulltransmuting a known null pointer into a reference
- uninit_assumed_initthis call for this type may be undefined behavior
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::self_assignmentself-assignment of `a.x` to `a.x`Read it next →Did this answer your question?