Skip to content

lint against "silent elision" in structs/enums/etc #45992

Closed

Description

@nikomatsakis

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:

struct Foo<'a> { x: &'a u32 }
fn foo(x: &Foo) {
//         ^^^ warning: hidden lifetime parameters are deprecated, try `Foo<'_>`
}

This should be fairly straightforward to do during resolve_lifetimes.

Activity

  1. changed the title [-]lint against "silent elision" in structs[/-] [+]lint against "silent elision" in structs/enums/etc[/+] on Nov 14, 2017
  2. Dylan-DPC-zz commented on Nov 15, 2017

    @Dylan-DPC-zz

    Interested in taking this up 😄

  3. nikomatsakis commented on Nov 16, 2017

    @nikomatsakis
    ContributorAuthor

    @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 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:

    self.resolve_elided_lifetimes(&params.lifetimes);

    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.

  4. nikomatsakis commented on Nov 16, 2017

    @nikomatsakis
    ContributorAuthor

    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. =)

  5. nikomatsakis commented on Nov 22, 2017

    @nikomatsakis
    ContributorAuthor

    @Dylan-DPC how goes? Did you get a chance to take a look?

  6. Dylan-DPC-zz commented on Nov 22, 2017

    @Dylan-DPC-zz

    Hey Niko. Was busy. Will try it by this weekend.

  7. nikomatsakis commented on Feb 5, 2018

    @nikomatsakis
    ContributorAuthor

    fixed in #46254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions