Skip to content

Lifetime parameters are silently deleted #42115

Closed

Description

@djzin

This compiles:

fn lifetime<'a>()
    where &'a (): 'a
{
    /* do nothing */
}

fn main() {
    lifetime::<'static>()
}

as does this:

fn lifetime<'a>() {} 
fn main() {
    lifetime();
}

but this fails:

fn lifetime<'a>() {}
fn main() {
    lifetime::<'static>();
}
rustc 1.19.0-nightly (5dfcd85fd 2017-05-19)
error[E0088]: too many lifetime parameters provided: expected at most 0 lifetime parameters, found 1 lifetime parameter
 --> <anon>:3:5
  |
3 |     lifetime::<'static>();
  |     ^^^^^^^^^^^^^^^^^^^ expected 0 lifetime parameters

error: aborting due to previous error

Activity

  1. eddyb commented on Jun 7, 2017

    @eddyb
    Contributor

    They become late-bound when not used in bounds or are used only the return type.
    cc @nikomatsakis We should really do something about this.

  2. nikomatsakis commented on Jun 7, 2017

    @nikomatsakis
    Contributor

    Yeah the current situation is pretty goofy. It'd probably be best if we could report an error when providing lifetimes unless you provide all of them (late and early bound) -- at minimum, for now, we could just make it an error to specify lifetimes if any of them are late bound.

    Nominating so this doesn't get lost. I'm a bit nervous because of backwards compatibility. (In fact, I already recommended to @jdm a hack that relied on the current behavior.)

  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 7, 2017
  4. nikomatsakis commented on Jun 7, 2017

    @nikomatsakis
    Contributor

    Purpose of nomination is to try and decide how we should handle this and how to prioritize.

  5. nikomatsakis commented on Jun 8, 2017

    @nikomatsakis
    Contributor

    triage: P-medium

    This situation has been a problem for a long time in various forms, and is a bit obscure, but nonetheless current situation is not great. To some extent this is also a @rust-lang/lang question.

  6. nikomatsakis commented on Jun 8, 2017

    @nikomatsakis
    Contributor

    I'm going to change to T-lang. There are definitely some thorny questions here.

  7. added
    T-langRelevant to the language team
    and removed
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 8, 2017
  8. nikomatsakis commented on Jun 15, 2017

    @nikomatsakis
    Contributor

    Discussed in the @rust-lang/lang meeting -- we agree that restricting to 100% early-bound is the right thing here. As proposed in #42492

  9. nikomatsakis commented on Jun 15, 2017

    @nikomatsakis
    Contributor

    triage: P-high

  10. added
    P-highHigh priority
    and removed on Jun 15, 2017
  11. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 15, 2017
  12. nikomatsakis commented on Jun 15, 2017

    @nikomatsakis
    Contributor

    @petrochenkov since you agreed to take a stab at that lint, I'm assigning you to the issue for now :) hope that's ok

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

Metadata

Metadata

Assignees

Labels

P-highHigh priorityT-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