Skip to content

[nll] improve the "fully elaborated type" case in region errors #52533

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

Closed
nikomatsakis opened this issue Jul 19, 2018 · 0 comments
Closed

[nll] improve the "fully elaborated type" case in region errors #52533

nikomatsakis opened this issue Jul 19, 2018 · 0 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal

Comments

@nikomatsakis
Copy link
Contributor

Consider this example:

#![feature(nll)]

fn foo(_: impl for<'a> FnOnce(&'a u32, &u32) -> &'a u32) {
}

fn main() {
    foo(|a, b| b)
}

Here, we are returning b from the closure but we ought to be returning a. We get this error message, which could be much clearer:

error: unsatisfied lifetime constraints
 --> src/main.rs:8:16
  |
8 |     foo(|a, b| b)
  |          -  -  ^ free region requires that `'1` must outlive `'2`
  |          |  |
  |          |  lifetime `'1` appears in this argument
  |          lifetime `'2` appears in this argument

There are a number of problems here, but the part I wanted to focus on in this issue is the message "lifetime '1 appears in this argument".

This message occurs when we fail, for whatever reason, to identify part of the type that we can highlight. For example, if we compare against the case where we have given type annotations in the closure, we can see that in that case we do better:

error: unsatisfied lifetime constraints
 --> src/main.rs:8:28
  |
8 |     foo(|a: &u32, b: &u32| b)
  |             -        -     ^ free region requires that `'1` must outlive `'2`
  |             |        |
  |             |        let's call the lifetime of this reference `'1`
  |             let's call the lifetime of this reference `'2`

The goal of this issue is to do better in this case where no type annotations are available. We've been discussing this on an internals thread and there have been a number of helpful suggestions. I think for the purposes of this issue the wording isn't that important, I'm mostly interested in producing the "fully elaborated type" print out. So let's go with something simple like this as our goal:

error: unsatisfied lifetime constraints
 --> src/main.rs:8:16
  |
8 |     foo(|a, b| b)
  |          -  -  ^ free region requires that `'1` must outlive `'2`
  |          |  |
  |          |  has type `&'1 u32`
  |          has type `&'2 u32`
@nikomatsakis nikomatsakis added A-NLL Area: Non-lexical lifetimes (NLL) WG-compiler-nll NLL-diagnostics Working towards the "diagnostic parity" goal A-diagnostics Area: Messages for errors, warnings, and lints labels Jul 19, 2018
@davidtwco davidtwco self-assigned this Jul 22, 2018
bors added a commit that referenced this issue Jul 27, 2018
[nll] improve the "fully elaborated type" case in region errors

Fixes #52533.

r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal
Projects
None yet
Development

No branches or pull requests

2 participants