Closed
Description
I tried this code:
let domain = "foobar.de";
// Original code
let x = domain
.rsplitn(2, '.')
.next()
.expect("The domain is never empty, thus one substring always exists.");
dbg!(x); // => prints "de"
clippy correctly emits a warning for the manual_split_once
lint, however, the suggestion is wrong even though the lint is marked as MachineApplicable
.
clippy suggests this replacement:
domain
.rsplitn(2, '.')
.next()
// ==>
Some(domain.rsplit_once('.').map_or(domain, |x| x.0))
The suggestion is wrong, and it should be x.1
at the end. The original code prints "de" while the new one prints "foobar", which you can see in this playground.
Meta
Rust version (rustc -Vv
):
rustc 1.55.0 (c8dfcfe04 2021-09-06)
binary: rustc
commit-hash: c8dfcfe046a7680554bf4eb612bad840e7631c4b
commit-date: 2021-09-06
host: x86_64-unknown-linux-gnu
release: 1.55.0
LLVM version: 12.0.1