Closed
Description
Given the following code:
fn foo(d: impl Sized, p: &mut ()) -> impl Sized + '_ {
(d, p)
}
The current output is:
error[E0311]: the parameter type `impl Sized` may not live long enough
--> src/lib.rs:2:5
|
2 | (d, p)
| ^^^^^^
|
note: the parameter type `impl Sized` must be valid for the anonymous lifetime defined here...
--> src/lib.rs:1:26
|
1 | fn foo(d: impl Sized, p: &mut ()) -> impl Sized + '_ {
| ^^^^^^^
note: ...so that the type `impl Sized` will meet its required lifetime bounds
--> src/lib.rs:2:5
|
2 | (d, p)
| ^^^^^^
help: consider adding an explicit lifetime bound...
|
1 | fn foo(d: 'a, impl Sized + 'a, p: &mut ()) -> impl Sized + '_ {
Not only the suggested syntax is invalid, it also suggests introducing a fresh lifetime parameter instead of naming the elided one on p
.
Ping @estebank.
@rustbot modify labels: +A-suggestion-diagnostics +D-invalid-suggestion
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Lifetimes / regionsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.