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

Unused lifetime type parameters #877

Closed
regexident opened this issue Apr 24, 2016 · 8 comments
Closed

Unused lifetime type parameters #877

regexident opened this issue Apr 24, 2016 · 8 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-unnecessary Lint: Warn about unnecessary code T-middle Type: Probably requires verifiying types

Comments

@regexident
Copy link

Leaving an unused type parameter …

struct Foo;

impl<T> Foo {
    fn foo() {}
}

… triggers the following error:

error: the type parameter `T` is not constrained
by the impl trait, self type, or predicates [E0207]

Leaving an unused lifetime parameter however …

struct Bar;

impl<'a> Bar {
    fn bar() {}
}

does not.

We should lint these, shouldn't we? Or should I file a rustc bug report?

@llogiq
Copy link
Contributor

llogiq commented Apr 24, 2016

There's the unused_lifetimes lint. Doesn't that catch your case?

@regexident
Copy link
Author

regexident commented Apr 24, 2016

No, apparently it doesn't.

This …

impl<'a> Bar {
    fn foo<'b>() { }
}

… only triggers one clippy warning. For fn foo:

src/lib.rs:4:12: 4:14 warning: this lifetime isn't used in the function definition,
#[warn(unused_lifetimes)] on by default
src/lib.rs:4     fn foo<'b>() { }
                        ^~
src/lib.rs:4:12: 4:14 help: for further information visit
https://github.com/Manishearth/rust-clippy/wiki#unused_lifetimes

@llogiq
Copy link
Contributor

llogiq commented Apr 24, 2016

Ok, so this should be an extension to the unused_lifetimes lint that should also check ImplItems (and probably TraitImplItems), which it currently apparently does not.

@birkenfeld
Copy link
Contributor

I'll note that this behavior is currently pretty nice for writing macros that handle reference and non-reference types, because it saves you some contortions that come from the fact that there is no macro matcher for Generics.

Of course, for clippy, that doesn't really matter since we'd exclude macro expansions anyway.

@oli-obk oli-obk added L-unnecessary Lint: Warn about unnecessary code E-medium Call for participation: Medium difficulty level problem and requires some initial experience. C-bug Category: Clippy is not doing the correct thing T-middle Type: Probably requires verifiying types C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages and removed C-bug Category: Clippy is not doing the correct thing labels May 10, 2017
etaoins added a commit to etaoins/arret that referenced this issue Oct 16, 2018
@varkor
Copy link
Member

varkor commented Jun 10, 2019

The unused_lifetimes lint now captures the example in #877 (comment), so it might now be sufficient.

@flip1995
Copy link
Member

flip1995 commented Jun 10, 2019

Is this a new addition to the rustc lint, that hasn't made it into the playground yet? Since it doesn't get linted on the Playground.

@varkor
Copy link
Member

varkor commented Jun 10, 2019

@flip1995: you were missing the !s — here's a working link.

@flip1995
Copy link
Member

Ohhhhh, sorry 🤦‍♂️ Then this can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-unnecessary Lint: Warn about unnecessary code T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

6 participants