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

Lint overcapturing in impl Trait on 2024 edition #131943

Open
GoldsteinE opened this issue Oct 19, 2024 · 1 comment
Open

Lint overcapturing in impl Trait on 2024 edition #131943

GoldsteinE opened this issue Oct 19, 2024 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@GoldsteinE
Copy link
Contributor

GoldsteinE commented Oct 19, 2024

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.

@GoldsteinE GoldsteinE added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 19, 2024
@compiler-errors
Copy link
Member

Yeah, makes sense. I could implement such a lint.

@rustbot claim

@jieyouxu jieyouxu added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants