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

Malformed suggestion for filling in multiple placeholder return lifetimes #84592

Closed
wabain opened this issue Apr 26, 2021 · 0 comments · Fixed by #85050
Closed

Malformed suggestion for filling in multiple placeholder return lifetimes #84592

wabain opened this issue Apr 26, 2021 · 0 comments · Fixed by #85050
Labels
C-bug Category: This is a bug.

Comments

@wabain
Copy link
Contributor

wabain commented Apr 26, 2021

Playground.

I tried this code:

struct TwoLifetimes<'x, 'y> {
    x: &'x (),
    y: &'y (),
}

fn two_lifetimes_needed(a: &(), b: &()) -> TwoLifetimes<'_, '_> {
    TwoLifetimes { x: &(), y: &() }
}

I expected to see an error message suggesting adding a named lifetime 'a to the returned type TwoLifetimes<'a, 'a>.

Instead, the suggested substitution is the malformed TwoLifetimes<'_<'a, 'a>, '_>.

error[E0106]: missing lifetime specifiers
  --> src/main.rs:11:57
   |
11 | fn two_lifetimes_needed(a: &(), b: &()) -> TwoLifetimes<'_, '_> {
   |                            ---     ---                  ^^ expected 2 lifetime parameters
   |
   = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `a` or `b`
help: consider introducing a named lifetime parameter
   |
11 | fn two_lifetimes_needed<'a>(a: &'a (), b: &'a ()) -> TwoLifetimes<'_<'a, 'a>, '_> {
   |                        ^^^^    ^^^^^^     ^^^^^^                  ^^^^^^^^^^

The linked playground shows that the output is correct when the return type lifetimes are elided (a bare TwoLifetimes), and also if only one placeholder lifetime is used (OneLifetime<'_>).

Meta

Reproduced on 1.53.0-nightly (2021-04-25 3709ae3), on 1.51.0 stable, and 1.47.0 stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant