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

Traits allow unused generic parameters #37496

Closed
steveklabnik opened this issue Oct 31, 2016 · 8 comments
Closed

Traits allow unused generic parameters #37496

steveklabnik opened this issue Oct 31, 2016 · 8 comments
Labels
A-lifetimes Area: Lifetimes / regions A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-trait-system Area: Trait system A-type-system Area: Type system T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@steveklabnik
Copy link
Member

Consider this trait:

trait Foo<'a> {
  fn foo(x: i32, y: i32) -> i32;
}

rustc will happily let this compile, even though 'a is never used for anything. The same goes for type parameters. This feels incorrect to me, though I might be wrong.

@steveklabnik steveklabnik added A-type-system Area: Type system A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system T-lang Relevant to the language team, which will review and decide on the PR/issue. A-lang labels Oct 31, 2016
@sanxiyn
Copy link
Member

sanxiyn commented Oct 31, 2016

Bear with me if I sound bitter, because I am. No one other than @steveklabnik closed #25871 last February. I will not close this issue, because I am better than him.

@steveklabnik
Copy link
Member Author

steveklabnik commented Nov 1, 2016

@sanxiyn that issue was closed as part of a blanket policy on lints, it wasn't anything personal. If this issue were "we should make a lint for this", I wouldn't have made it in the first place. Furthermore, I didn't close your PR at all. it was closed due to a lack of activity by alex.

This issue is "I'm not even sure this code should be valid." If it is, then this should be closed, just as that issue was closed.

@arielb1
Copy link
Contributor

arielb1 commented Nov 1, 2016

I don't see why this should not be valid - for example, marker traits have an unused Self by this standard.

@steveklabnik
Copy link
Member Author

@arielb1 would it? Marker traits don't take any generic parameters. Is it that Self is treated as one or something?

@sanxiyn
Copy link
Member

sanxiyn commented Nov 2, 2016

It was implemented as a lint because unused generic parameters, in general, is not an error. An example is _assert_error_is_sync_send in libstd. I think it is a legitimate use case.

That said, maybe unused lifetime parameters, or unused generic parameters in traits, are useless. I can easily rebase my PR restricted to these cases.

@arielb1
Copy link
Contributor

arielb1 commented Nov 2, 2016

@steveklabnik

Sure enough. Self is conceptually a generic parameter.

@eddyb
Copy link
Member

eddyb commented Nov 12, 2016

They're not useless, they can have semantic implications, for example unsafe traits which may be used to determine the safety of an otherwise problematic operation.
One such trait (although not unsafe, as only the compiler can implement it) is Unsize.
T: Unsize<U> means that any (even smart) pointer to T may be coerced to the same pointer to U, turning a thin pointer into a fat pointer most of the time.

@arielb1 arielb1 added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 23, 2017
@arielb1
Copy link
Contributor

arielb1 commented Jan 23, 2017

Unsize is a magic trait, but I don't think this is anything more than a Clippy lint.

@arielb1 arielb1 closed this as completed Jan 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-trait-system Area: Trait system A-type-system Area: Type system T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants