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

region error messages involving impls are confusing #52742

Closed
nikomatsakis opened this issue Jul 26, 2018 · 5 comments
Closed

region error messages involving impls are confusing #52742

nikomatsakis opened this issue Jul 26, 2018 · 5 comments
Assignees
Labels
A-NLL Area: Non Lexical Lifetimes (NLL) NLL-diagnostics Working torwads the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jul 26, 2018

#![feature(nll)]
#![feature(in_band_lifetimes)]
#![feature(impl_header_lifetime_elision)]

struct Foo<'a, 'b> {
    x: &'a u32,
    y: &'b u32,
}

struct Bar<'b> {
    z: &'b u32
}

impl Foo<'_, '_> {
    fn take_bar(&mut self, b: Bar<'_>) {
        self.y = b.z
    }
}

fn main() { }

produces this confusing error:

error[E0621]: explicit lifetime required in the type of `b`
  --> src/main.rs:15:9
   |
14 |     fn take_bar(&mut self, b: Bar<'_>) {
   |                            - consider changing the type of `b` to `Bar<'_>`
15 |         self.y = b.z
   |         ^^^^^^^^^^^^ lifetime `'_` required

I think the problem here is that the "nice region error" code is actually getting in the way of the NLL errors, which are better.

@nikomatsakis nikomatsakis added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-nll NLL-diagnostics Working torwads the "diagnostic parity" goal A-NLL Area: Non Lexical Lifetimes (NLL) labels Jul 26, 2018
@davidtwco davidtwco self-assigned this Jul 26, 2018
bors added a commit that referenced this issue Aug 6, 2018
Disable some nice region errors in NLL mode.

Fixes #52739. cc #52742.

r? @nikomatsakis
@nikomatsakis
Copy link
Contributor Author

Pulling out some comments from the Zulip thread. It is an interesting question what the output should look like.

Here are two possibilities:

error: unsatisfied lifetime constraints
  --> $DIR/issue-52742.rs:25:9
   |
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                 ---------         -- let's call this `'1`
   |                 |
   |                 has type `&mut Foo<'1, '_>`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ requires that `'1` must outlive `'2`
error: unsatisfied lifetime constraints
  --> $DIR/issue-52742.rs:25:9
   |
LL |  impl Foo<'_, '_> {
  |            -- let's call this `'2`
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                                   -- let's call this `'1`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ requires that `'1` must outlive `'2`

It's also interesting to consider the case where we have a named, in-band lifetime:

error: unsatisfied lifetime constraints
  --> $DIR/issue-52742.rs:25:9
   |
LL |  impl Foo<'tcx, '_> {
  |            ----`'tcx` declared here
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                                   -- let's call this `'1`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ requires that `'1` must outlive `'tcx`

@nikomatsakis
Copy link
Contributor Author

nikomatsakis commented Aug 6, 2018

I suppose you could imagine a hybrid:

error: unsatisfied lifetime constraints
  --> $DIR/issue-52742.rs:25:9
   |
LL |  impl Foo<'_, '_> {
  |            -- let's call this `'2`
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                 ---------         -- let's call this `'1`
   |                 |
   |                 has type `&mut Foo<'2, '_>`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ requires that `'1` must outlive `'2`

cramertj added a commit to cramertj/rust that referenced this issue Aug 8, 2018
region error messages involving impls are confusing

Part of rust-lang#52742.

r? @nikomatsakis
bors added a commit that referenced this issue Aug 9, 2018
region error messages involving impls are confusing

Part of #52742.

r? @nikomatsakis
bors added a commit that referenced this issue Aug 10, 2018
region error messages involving impls are confusing

Part of #52742.

r? @nikomatsakis
@nikomatsakis
Copy link
Contributor Author

We now get:

error: unsatisfied lifetime constraints
  --> src/main.rs:16:9
   |
15 |     fn take_bar(&mut self, b: Bar<'_>) {
   |                 ---------         -- let's call this `'1`
   |                 |
   |                 has type `&mut Foo<'_, '2>`
16 |         self.y = b.z
   |         ^^^^^^^^^^^^ requires that `'1` must outlive `'2`

This seems pretty reasonable. Going to mark as NLL-deferred for now.

@matthewjasper
Copy link
Contributor

nominating for discussion on whether this should be kept open

@nikomatsakis
Copy link
Contributor Author

Discussed in the NLL meeting and decided to close: seems like the current output is "good enough" for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non Lexical Lifetimes (NLL) NLL-diagnostics Working torwads the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants