Skip to content

WIP: add unnecessary_split_off lint #14814

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sebhernandezr
Copy link

@sebhernandezr sebhernandezr commented May 15, 2025

Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
changelog: none. Otherwise, please write a short comment
explaining your change.

It's also helpful for us that the lint name is put within backticks (` `),
and then encapsulated by square brackets ([]), for example:

changelog: [`lint_name`]: your change

If your PR fixes an issue, you can add fixes #issue_number into this
PR description. This way the issue will be automatically closed when
your PR is merged.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

  • Followed lint naming conventions
  • Added passing UI tests (including committed .stderr file)
  • cargo test passes locally
  • Executed cargo dev update_lints
  • Added lint documentation
  • Run cargo dev fmt

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.


fixes #4953

Please write a short comment explaining your change (or "none" for internal only changes)

changelog:

@andre-digiexam
Copy link

r? @llogiq

let &[arg] = args else {
return;
};
if clippy_utils::is_integer_literal(arg, 0) || clippy_utils::is_integer_const(cx, arg, 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter should be enough. Each literal is also a const


let vec5: Vec<_> = vec1.split_off(const { 0 });
//~^ unnecessary_split_off

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like to test

let zero = 0;
let vec6 = vec1.split_off(zero);

@llogiq
Copy link
Contributor

llogiq commented May 16, 2025

So you should look into clippy_utils/src/sym.rs which has a generate! macro call containing all our pre-interned symbols. You can add split_off there and directly use it to compare, which saves the .as_str() overhead. Also please edit the PR description to add a changelog line and squash your commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lint: Prefer mem::take over Vec::split_off(0)
3 participants