Lint overcapturing in impl Trait on 2024 edition
@compiler-errors is already working on this.
Since Oct 19, 2024.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
pub fn check(x: &[u8]) -> impl std::fmt::Display {
x[0]
}
Current output
(empty)
Desired output
A warning, like one produced by impl_trait_overcaptures.
Rationale and extra context
Currently, impl_trait_overcaptures lints code that would be overcapturing in edition = 2024 on editions < 2024. I think it would be valuable to add a (maybe allow-by-default) lint to detect overcapturing in new, edition 2024 code. Code like this is probably not meant to capture lifetime of x, so linting against this may help to avoid too-strict signatures. If the function was meant to be stricter than necessary (e.g. for future-compat reasons), you can always just #[allow] the lint.
Rust Version
$ rustc --version --verbose
rustc 1.83.0-nightly (eb4e23467 2024-10-09)
binary: rustc
commit-hash: eb4e2346748e1760f74fcaa27b42431e0b95f8f3
commit-date: 2024-10-09
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.1
Anything else?
Alternatively, this could be a Clippy lint. Having it in rustc could probably allow code reuse with the edition lint though.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.