You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
lint against "silent elision" in structs/enums/etc #45992
Now that support for '_ has landed, as part of #44524, it would be good to start linting for cases where it ought to be used. In particular, we wish to warn if there is a struct with lifetime parameters that are elided:
structFoo<'a>{x:&'au32}fnfoo(x:&Foo){// ^^^ warning: hidden lifetime parameters are deprecated, try `Foo<'_>`}
This should be fairly straightforward to do during resolve_lifetimes.
Sorry, I didn't get a chance to write up any instructions yesterday. I just took a look here and I think this should be fairly straightforward.
The first thing is that we need to add a lint. There are no perfect directions for adding a new lint that I can find. The best that I know of are in this forge document, under the section "Issuing future compatibility warnings". This section describes how to add a future compatibility lint. We don't want a future compatibility lint, just a regular lint, but most of the steps are the same. The one that does not apply is step 3 ,"Register the lint in src/librustc_lint/lib.rs". You can just skip that step.
Let's call the lint elided_lifetime_in_path. For now, let's set the default level to Allow, since we don't want to bothering people until the whole in-band lifetimes RFC is in place.
Once we have the lint, we want to modify the resolve_elided_lifetimes function in resolve_lifetimes.rs. We should add a deprecated: bool argument to it that indicates whether this elided lifetime occurs in a deprecated position.
Most of the callers can use false. The only one that is deprecated is this caller right here:
Then we just need to add some tests and we're done! To add tests, just make some ui tests that use lifetimes in the deprecated places (as well as places that are not deprecated) and write #![deny(elided_lifetime_in_path)] at the top.
We're also going to want to feature-gate this, though I don't think we have a good mechanism for that. We should figure that out. But let's do this first part first. =)
Activity
[-]lint against "silent elision" in structs[/-][+]lint against "silent elision" in structs/enums/etc[/+]Dylan-DPC-zz commentedon Nov 15, 2017
Interested in taking this up 😄
nikomatsakis commentedon Nov 16, 2017
@Dylan-DPC great =)
Sorry, I didn't get a chance to write up any instructions yesterday. I just took a look here and I think this should be fairly straightforward.
The first thing is that we need to add a lint. There are no perfect directions for adding a new lint that I can find. The best that I know of are in this forge document, under the section "Issuing future compatibility warnings". This section describes how to add a future compatibility lint. We don't want a future compatibility lint, just a regular lint, but most of the steps are the same. The one that does not apply is step 3 ,"Register the lint in
src/librustc_lint/lib.rs". You can just skip that step.Let's call the lint
elided_lifetime_in_path. For now, let's set the default level toAllow, since we don't want to bothering people until the whole in-band lifetimes RFC is in place.Once we have the lint, we want to modify the
resolve_elided_lifetimesfunction inresolve_lifetimes.rs. We should add adeprecated: boolargument to it that indicates whether this elided lifetime occurs in a deprecated position.Most of the callers can use
false. The only one that is deprecated is this caller right here:rust/src/librustc/middle/resolve_lifetime.rs
Line 948 in 88a28ff
Then we just need to add some tests and we're done! To add tests, just make some ui tests that use lifetimes in the deprecated places (as well as places that are not deprecated) and write
#![deny(elided_lifetime_in_path)]at the top.nikomatsakis commentedon Nov 16, 2017
We're also going to want to feature-gate this, though I don't think we have a good mechanism for that. We should figure that out. But let's do this first part first. =)
nikomatsakis commentedon Nov 22, 2017
@Dylan-DPC how goes? Did you get a chance to take a look?
Dylan-DPC-zz commentedon Nov 22, 2017
Hey Niko. Was busy. Will try it by this weekend.
nikomatsakis commentedon Feb 5, 2018
fixed in #46254
in which the elided-lifetimes-in-paths lint stops firing on `'_`
in which the elided-lifetimes-in-paths lint stops firing on `'_`