Skip to content

Lifetime parameters are silently deleted #42115

Closed
@djzin

Description

@djzin
Contributor

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

eddyb

eddyb commented on Jun 7, 2017

@eddyb
Member

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.

nikomatsakis

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

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

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.

nikomatsakis

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.

nikomatsakis

nikomatsakis commented on Jun 8, 2017

@nikomatsakis
Contributor

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

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
nikomatsakis

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

nikomatsakis

nikomatsakis commented on Jun 15, 2017

@nikomatsakis
Contributor

triage: P-high

11 remaining items

Loading
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

      Participants

      @eddyb@nikomatsakis@petrochenkov@rust-highfive@djzin

      Issue actions

        Lifetime parameters are silently deleted · Issue #42115 · rust-lang/rust