-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
When using find
and starts_with
the warning should obviously be suppressed.
Lint Name
indexing_slicing
Reproducer
I tried this code:
fn get_fallback(target: &str) -> Result<String, FallbackError> {
use FallbackError::*;
// find the scheme
let scheme = {
let colon = target.find(':').ok_or(NotAnUrl)?;
let scheme = &target[..colon];
if !scheme.starts_with("web+") {
return Err(NotAnUrl);
}
let scheme = &scheme[4..];
if is_scheme_invalid(scheme) {
return Err(NotAnUrl);
}
scheme
};
// bunch of other stuff
}
I saw this happen:
warning: slicing may panic
--> crates/api_common/src/request.rs:374:19
|
374 | let scheme = &target[..colon];
| ^^^^^^^^^^^^^^^
|
= help: consider using `.get(..n)`or `.get_mut(..n)` instead
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing
= note: requested on the command line with `-D clippy::indexing-slicing`
warning: slicing may panic
--> crates/api_common/src/request.rs:378:19
|
378 | let scheme = &scheme[4..];
| ^^^^^^^^^^^
|
= help: consider using `.get(n..)` or .get_mut(n..)` instead
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing
I expected to see this happen:
It should simply not.
Version
rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have