Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual_split_once lint causes a change in behaviour #7889

Closed
Marwes opened this issue Oct 27, 2021 · 0 comments · Fixed by #7896
Closed

manual_split_once lint causes a change in behaviour #7889

Marwes opened this issue Oct 27, 2021 · 0 comments · Fixed by #7896
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Marwes
Copy link

Marwes commented Oct 27, 2021

Lint name: manual_split_once

I tried this code:

path.rsplitn(2, '/').next().unwrap()

I expected to see this happen: cargo clippy should not suggest I change it to rsplit_once as that changes the behaviour.

Instead, this happened:

manual implementation of `rsplit_once`
   --> flux-core/src/semantic/nodes.rs:465:21
    |
465 |             None => path.rsplitn(2, '/').next().unwrap(),
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `path.rsplit_once('/').unwrap().1`
    |

cargo clippy --fix rewrote this to path.rsplit_once('/').unwrap().1 which is not equivalent code as rsplitn will always return at least one item, whereas rsplit_once will return None if the separator does not exist in the string causing the unwrap to panic.

path.rsplit_once('/').map_or(path, |t| t.1) would be a valid transformation.

Meta

Rust version (rustc -Vv):

rustc 1.58.0-nightly (e269e6bf4 2021-10-26)
binary: rustc
commit-hash: e269e6bf47f40c9046cd44ab787881d700099252
commit-date: 2021-10-26
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
@Marwes Marwes added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 27, 2021
@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label Oct 27, 2021
surechen added a commit to surechen/rust-clippy that referenced this issue Oct 29, 2021
Change manual_split_once's suggestion ".unwrap().1" after split_once or rsplit_once to .map_or("key=value", |x| x.1)

changelog: Change manual_split_once's suggestion ".unwrap().1" after split_once or rsplit_once to .map_or("key=value", |x| x.1)
surechen added a commit to surechen/rust-clippy that referenced this issue Oct 30, 2021
Change manual_split_once's suggestion ".unwrap().1" after split_once or rsplit_once to .map_or(.., |x| x.1).

changelog: Change manual_split_once's suggestion ".unwrap().1" after split_once or rsplit_once to .map_or(.., |x| x.1).
bors added a commit that referenced this issue Nov 17, 2021
Fix for #7889 and add new lint needless_splitn

fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
@bors bors closed this as completed in c051656 Nov 17, 2021
link2xt added a commit to deltachat/deltachat-core-rust that referenced this issue Dec 4, 2021
It's suggestions in stable 1.57 Rust are incorrect: rust-lang/rust-clippy#7889
link2xt added a commit to deltachat/deltachat-core-rust that referenced this issue Dec 4, 2021
It's suggestions in stable 1.57 Rust are incorrect: rust-lang/rust-clippy#7889
link2xt added a commit to deltachat/deltachat-core-rust that referenced this issue Dec 4, 2021
It's suggestions in stable 1.57 Rust are incorrect: rust-lang/rust-clippy#7889
link2xt added a commit to deltachat/deltachat-core-rust that referenced this issue Dec 4, 2021
* Remove unused os_name

* Disable clippy::manual_split_once lint

It's suggestions in stable 1.57 Rust are incorrect: rust-lang/rust-clippy#7889

* Allow unused fields in OAuth2 response

* Fix clippy warning about `select_pk_for_encryption`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants