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

Update E0088 to new format #36208

Closed
wants to merge 1 commit into from
Closed

Update E0088 to new format #36208

wants to merge 1 commit into from

Conversation

yossi-k
Copy link
Contributor

@yossi-k yossi-k commented Sep 2, 2016

Fixes #35226.
Part of #35233.

r? @jonathandturner

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jonathandturner (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

count(lifetimes.len()));
match lifetime_defs.len() {
0 => err.span_label(span, &format!("unexpected lifetime parameter")),
_ => err.span_label(span, &format!("{} lifetime parameters expected",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we handle multiple cases, can you add to the unit test to check for these new cases?

@sophiajt
Copy link
Contributor

sophiajt commented Sep 2, 2016

Thanks for the PR!

Looks like we'll need to test for some of your new cases. After that I think we're probably good to go.

@yossi-k
Copy link
Contributor Author

yossi-k commented Sep 3, 2016

@jonathandturner I'm not much of a rust expert, but does the second case make sense? I can't think of a code to trigger this, perhaps you can point me in some useful direction?

@sophiajt
Copy link
Contributor

sophiajt commented Sep 4, 2016

You could try an example that tests against two different functions, one with a lifetime and one without. Something like:

fn f() {}

fn g<'a>() {}

fn main() {
    f::<'static>(); //~ ERROR E0088
    //~^ unexpected lifetime parameter

    g::<'static, 'static>();
}

@yossi-k
Copy link
Contributor Author

yossi-k commented Sep 4, 2016

@jonathandturner That was also my first guess, but g doesn't expect any lifetimes at all, we need something that expects more than zero.

@sophiajt
Copy link
Contributor

sophiajt commented Sep 4, 2016

@yossi-k - looks like you're right. When I try it with functions, the lifetime parameters seem to be ignored. If I try it with traits, I just get a different error message:

fn f() {}

fn g<'a>(x: i32) -> &'a str {}

trait Foo<'a> { }

fn main() {
    f::<'static>(); //~ ERROR E0088
    //~^ unexpected lifetime parameter

    g::<'static, 'static>(4);

    let x: Foo<'static, 'static>;
}

It may not be possible to invoke the code path. If that's the case, it may make sense to always say "unexpected lifetime parameters" in the label

@yossi-k
Copy link
Contributor Author

yossi-k commented Sep 4, 2016

@jonathandturner So considering that it doesn't seem possible to actually provide a lifetime parameter to a function, and providing lifetimes to other things (such as traits) is covered by a whole different set of errors (e.g. E0107), is this code segment actually needed?

@sophiajt
Copy link
Contributor

sophiajt commented Sep 5, 2016

@yossi-k - you could try taking it out and running the unit test suite again and see what happens. If all of the errors are still caught by E0107, you might be right. And it would help us simplify things.

@yossi-k
Copy link
Contributor Author

yossi-k commented Sep 8, 2016

@jonathandturner All tests seem to pass, so I'm guessing we're okay.
Also I merged the Spans of all provided lifetime parameters.

@sophiajt
Copy link
Contributor

sophiajt commented Sep 8, 2016

@yossi-k - unfortunately, you can't safely merge multiple spans together, since spans can come from macros and might give you a broken span as a result.

@yossi-k
Copy link
Contributor Author

yossi-k commented Sep 8, 2016

@jonathandturner What should I do in this case? Only reference one lifetime parameter, perhaps each individually or maybe just the entire function call?

@sophiajt
Copy link
Contributor

@yossi-k - I just added a way to safely merge spans to CodeMap. It's a new method called merge_spans that will merge the spans if it's safe to do so.

@sophiajt
Copy link
Contributor

@yossi-k - after working some with @GuillaumeGomez, I think a better solution than merging spans would be to instead point at the argument when it's unexpected. You can see an example on E0050

@GuillaumeGomez
Copy link
Member

@jonathandturner: It hasn't been updated yet. :p

@sophiajt
Copy link
Contributor

@GuillaumeGomez - moved it from a comment to the issue text. Should be updated now

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to resubmit with a rebase!

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Nov 20, 2016
@eddyb
Copy link
Member

eddyb commented Jan 5, 2017

@jonathandturner You should've asked a rustc developer 😭. This (through #37835) introduced a regression which I only found because I was rewriting lifetime elision and I had to update this check.

Thankfully it's only propagated to beta so we can just backport a fix, but this is scary that it just happened.
Well, not that scary, what will happen is inference variables will be created for the missing lifetimes.

What's confusing here is the distinction between early-bound and late-bound fn lifetime parameters.
Early-bound lifetime parameters work like they do in type definitions, they get passed in the path and applied to the type to get the type of the path, and all uses of the resulting value get the same lifetime.
They only end up existing when the syntactic lifetime is used in a bound (e.g. 'b: 'a and T: Trait<'a>).

Late-bound lifetimes, explicitly expressed by for<'a> when nested in types, are the most common case, and they allow a signature to stay generic (and work with e.g. Fn(&T) aka for<'a> Fn(&'a T)).

For some historical reason or another, we ended up mapping lifetimes passed to a path to only the early-bound lifetimes and have no mechanism for "downgrading" late- to early-bound for paths with lifetimes.
We may want to change to something like this, I'm not sure (explicit lifetimes to value paths are rare IME).

To wrap it up, this is the test I used (errors on 1.14 stable, incorrectly passes on beta/nightly):

fn foo<'a: 'b, 'b: 'a>() {}
fn main() {
    foo::<'static>();
}

cc @rust-lang/compiler @rust-lang/lang

@arielb1
Copy link
Contributor

arielb1 commented Jan 5, 2017

For some historical reason or another, we ended up mapping lifetimes passed to a path to only the early-bound lifetimes and have no mechanism for "downgrading" late- to early-bound for paths with lifetimes.

That's just an implementation artifact, methinks.

@sophiajt
Copy link
Contributor

sophiajt commented Jan 5, 2017

@eddyb - you're commenting on a closed PR, I assume you meant the merged one?

Glad we could catch it in time. Looking at it now, definitely an oversight on my part. Clearly they changed the logic rather than just changing the message.

@sophiajt sophiajt mentioned this pull request Jan 5, 2017
@sophiajt
Copy link
Contributor

sophiajt commented Jan 5, 2017

@eddyb - potential fix at #38859

bors added a commit that referenced this pull request Jan 6, 2017
E0088/E0090 fix

This fixes an issue reported by @eddyb (#36208 (comment)) where the check for "too few lifetime parameters" was removed in one of the error message PRs.

I also removed the span shrinking from E0088, as early bound lifetimes give you a confusing underline in some cases.

r=eddyb
bors added a commit that referenced this pull request Jan 7, 2017
E0088/E0090 fix

This fixes an issue reported by @eddyb (#36208 (comment)) where the check for "too few lifetime parameters" was removed in one of the error message PRs.

I also removed the span shrinking from E0088, as early bound lifetimes give you a confusing underline in some cases.

r=eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants