-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.