Malformed suggestion for filling in multiple placeholder return lifetimes · Issue #84592 · rust-lang/rust (original) (raw)
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.