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

Lifetime error with #![feature(nll)] and RPIT gives bad suggestion #73159

Closed
Aaron1011 opened this issue Jun 9, 2020 · 0 comments · Fixed by #89504
Closed

Lifetime error with #![feature(nll)] and RPIT gives bad suggestion #73159

Aaron1011 opened this issue Jun 9, 2020 · 0 comments · Fixed by #89504
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. NLL-diagnostics Working towards the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

The following code:

#![feature(nll)]

struct Foo<'a>(&'a [u8]);

impl<'a> Foo<'a> {
    fn make_it(&self) -> impl Iterator<Item = u8> {
        self.0.iter().copied()
    }
}

gives the following error:

error: lifetime may not live long enough
 --> src/lib.rs:6:26
  |
5 | impl<'a> Foo<'a> {
  |      -- lifetime `'a` defined here
6 |     fn make_it(&self) -> impl Iterator<Item = u8> {
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'a` must outlive `'static`
  |
  = help: consider replacing `'a` with `'static`

Suggsting that the user change the impl to impl Foo<'static> is usually the wrong thing to do - it's more likely that the user wants to write impl Iterator<Item = u8> + 'a

@Aaron1011 Aaron1011 added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. NLL-diagnostics Working towards the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 9, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 5, 2021
…tsakis

Don't suggest replacing region with 'static in NLL

Fixes rust-lang#73159

This is similar to rust-lang#69350 - if the user didn't initially
write out a 'static lifetime, adding 'static in response to
a lifetime error is usually the wrong thing to do.
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 5, 2021
…tsakis

Don't suggest replacing region with 'static in NLL

Fixes rust-lang#73159

This is similar to rust-lang#69350 - if the user didn't initially
write out a 'static lifetime, adding 'static in response to
a lifetime error is usually the wrong thing to do.
@bors bors closed this as completed in fdd8a0d Oct 5, 2021
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-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. NLL-diagnostics Working towards the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant