Skip to content

False positive unused_lifetime #141784

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

Open
matthiaskrgr opened this issue May 30, 2025 · 1 comment
Open

False positive unused_lifetime #141784

matthiaskrgr opened this issue May 30, 2025 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-unused_lifetimes Lint: unused_lifetimes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

I tried this code:

#![warn(unused_lifetimes)]
struct S;

pub fn repro()
    where
        for<'a> S: Clone,
    {
    }
    
pub fn main() {}

=>

warning: lifetime parameter `'a` never used
 --> src/main.rs:6:13
  |
6 |         for<'a> S: Clone,
  |         ----^^-- help: elide the unused lifetime
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(unused_lifetimes)]

suggested code (cargo fix)

#![warn(unused_lifetimes)]
struct S;

pub fn repro()
    where
        S: Clone,
    {
    }
    
pub fn main() {}

does not compile:

error[E0277]: the trait bound `S: Clone` is not satisfied
 --> src/main.rs:6:9
  |
6 |         S: Clone,
  |         ^^^^^^^^ the trait `Clone` is not implemented for `S`
  |
  = help: see issue #48214
help: consider annotating `S` with `#[derive(Clone)]`
  |
2 + #[derive(Clone)]
3 | struct S;
  |
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
  |
2 + #![feature(trivial_bounds)]
  |

For more information about this error, try `rustc --explain E0277`.
error: could not compile `f` (bin "f") due to 1 previous error
rustc 1.89.0-nightly (1bbd62e54 2025-05-29)
binary: rustc
commit-hash: 1bbd62e547ba5cc08ccb44c27def3d33195d2dd5
commit-date: 2025-05-29
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label May 30, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 30, 2025
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels May 30, 2025
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 30, 2025
@jieyouxu jieyouxu added L-false-positive Lint: False positive (should not have fired). L-unused_lifetimes Lint: unused_lifetimes and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. L-false-positive Lint: False positive (should not have fired). labels May 30, 2025
@Noratrieb Noratrieb changed the title FP unused_lifetime False positive unused_lifetime May 30, 2025
@Noratrieb
Copy link
Member

This is definitely an abuse of higher ranked trait bounds, so I don't think the lint should handle this

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 C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-unused_lifetimes Lint: unused_lifetimes 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

4 participants