Skip to content

Clippy: Clean remaining low-hanging fruit#87

Merged
ltratt merged 6 commits into
ltratt:masterfrom
hseg:clippy-redux
May 24, 2026
Merged

Clippy: Clean remaining low-hanging fruit#87
ltratt merged 6 commits into
ltratt:masterfrom
hseg:clippy-redux

Conversation

@hseg
Copy link
Copy Markdown
Contributor

@hseg hseg commented May 15, 2026

These are about previously-unaddressed lints, but are mostly straightforward. The last two commits might be more controversial:

  • Documenting the need for collect() is obvious, but works around that lint being fragile and giving false positives. The alternative is to keep that disabling around, but that seems noisier. I've marked the exception with #[expect] so that it will be flagged for removal once the lint is fixed.
  • Rust 2018 changed the idiom to disallow using types with lifetimes without mentioning their lifetime parameters. All use sites in the codebase can be inferred, so setting the lifetime parameters there to '_ did the trick, but that does make the code a little more noisy. Still, the reminder might be useful, so I'd argue following the idiom makes sense.

Closes: #86 (this PR is rebased on that one, assuming both will be merged, with #86 coming first)

hseg added 4 commits May 15, 2026 18:23
More uniform with other empty values
Protect against type changes in the scrutinee
Also remove unnecessary clones (Instant impls Copy)

Cannot enable lints until [grmtools#639] is merged since the generated
code for the lexer will cause these to unblockably complain.

When it is, re-enable implicit_clone and redundant_clone

[grmtools#639]: softdevteam/grmtools#639
@ltratt
Copy link
Copy Markdown
Owner

ltratt commented May 15, 2026

You are right: the last two are controversial :)

I think the collect one shows that warning is simply not useful, and we simply shouldn't try enabling it.

In terms of lifetime annotations, I don't know that there's any advantage to explicit <'_> in these cases, other than bloating the source code a bit? I am prepared to be convinced on the latter, though.

@hseg
Copy link
Copy Markdown
Contributor Author

hseg commented May 16, 2026 via email

@ltratt
Copy link
Copy Markdown
Owner

ltratt commented May 17, 2026

Given there is only one false positive, the cost difference between local and global opt outs is pretty much the same.

Understood. I'm going to come down in favour of the global opt out, because if that same idiom crops up in the code, I don't think the author should be burdened by a false positive that they then have to investigate.

Overall, this suggests to me this is a tarball of a lint that might be addressed if and when I get a better handle on it, but can be removed from this PR for the moment.

FWIW, I agree.

OK, so then I suggest: let's remove the last two commits from this PR, add that global opt out, do a cargo fmt, then we're good to merge.

hseg added 2 commits May 24, 2026 23:27
Specifically in our case, its integration with borrow checking is buggy,
so causes pointless false positives. See eg
rust-lang/rust-clippy#6066
Original motivation for this lint was cases like
fn(&T) -> UnclearLifetime
where the lifetime of the output type wasn't obvious without diving into
the implementation (and it could thus hide a hidden dependency on the
&T). The lint as written is a very blunt instrument, and also covers the
innocuous fn(ContainsLifetime) -> NoLifetime case we have throughout the
codebase.
Work is being done to narrow the scope of the lint, and in particular to
make our usecase accepted, so disable it globally for now.

See also:
rust-lang/rust#91639 (comment)
rust-lang/rust#120808
https://rust-lang.zulipchat.com/#narrow/channel/213817/near/528092054
@hseg
Copy link
Copy Markdown
Contributor Author

hseg commented May 24, 2026

OK, done. FWIW, I believe the needless_collect lint can be reenabled once rust-lang/rust-clippy#6066 is fixed.

I also wrote up my understanding of the situation around elided_lifetimes_in_paths in the commit message and more briefly in Cargo.toml. It seems that once rust-lang/rust#120808 lands, we won't need to explicitly disable it anymore, since the cases it currently complains about will be allow-by-default under it.

@hseg
Copy link
Copy Markdown
Contributor Author

hseg commented May 24, 2026

I do still think I might rework the logic in the needless_collect case regardless, it does look like it could be written more iterator-heavily. But that's work for a future PR.

@hseg
Copy link
Copy Markdown
Contributor Author

hseg commented May 24, 2026

Was a bit busy last week, sorry for the delay.

@ltratt
Copy link
Copy Markdown
Owner

ltratt commented May 24, 2026

Thanks!

@ltratt ltratt merged commit 9829943 into ltratt:master May 24, 2026
5 checks passed
@hseg hseg deleted the clippy-redux branch May 24, 2026 20:56
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.

2 participants