Skip to content

E0311 references nonexistant lifetime #101027

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
lcnr opened this issue Aug 26, 2022 · 0 comments · Fixed by #101445
Closed

E0311 references nonexistant lifetime #101027

lcnr opened this issue Aug 26, 2022 · 0 comments · Fixed by #101445
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Aug 26, 2022

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d55c130a01f69dede262830dd4771bdf

fn no_restriction<T>(x: &()) -> &() {
    with_restriction::<T>(x)
}

fn with_restriction<'b, T: 'b>(x: &'b ()) -> &'b () {
    x
}

The current output is:

error[E0311]: the parameter type `T` may not live long enough
 --> src/lib.rs:2:5
  |
2 |     with_restriction::<T>(x)
  |     ^^^^^^^^^^^^^^^^^^^^^
  |
note: the parameter type `T` must be valid for the anonymous lifetime defined here...
 --> src/lib.rs:1:25
  |
1 | fn no_restriction<T>(x: &()) -> &() {
  |                         ^^^
note: ...so that the type `T` will meet its required lifetime bounds
 --> src/lib.rs:2:5
  |
2 |     with_restriction::<T>(x)
  |     ^^^^^^^^^^^^^^^^^^^^^
help: consider adding an explicit lifetime bound...
  |
1 | fn no_restriction<T: 'a>(x: &()) -> &() {
  |                    ++++

'a does not exist, maybe it should get introduced by the diagnostic

@lcnr lcnr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 26, 2022
@TaKO8Ki TaKO8Ki self-assigned this Aug 26, 2022
@bors bors closed this as completed in 7c7548c Sep 6, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

2 participants