Open
Description
In some cases, we can suggest a new signature where the user introduces a new named lifetime. This is a bit tricky to figure out how to format the suggestion. It would get mildly easier with rust-lang/rfcs#2115.
struct Ref<'a> { x: &'a u32 }
fn foo<T>(mut x: Vec<Ref<T>>, data: u32, y: Ref<T>) {
x.push(y);
}
The old code used to produce a modified form of the HIR to format the suggestion. I'd prefer not to do that. I was thinking we could probably do something simpler where we just emit the "new parts" of the signature, maybe like this?
hint: consider changing the signature as shown:
| fn foo<'a, ...>(mut x: Vec<Ref<'a, T>>, ..., y: Ref<'a, T>)
Idea would be to do something like this:
- Find name for a fresh lifetime that is not in scope (e.g.,
'``a
) - Emit
fn
- Emit name of function (
foo
) - If the function has generic parameters already:
- Emit
<
, fresh lifetime,…
,>
- Emit
- Else:
- Emit
<
, fresh lifetime,>
- Emit
- Emit
(
- Emit
…
if needed - Emit parameter name 1 and type (with fresh lifetime substituted)
- Emit
…
if needed - Emit parameter name 2 and type (with fresh lifetime substituted)
- Emit
…
if needed - Emit
)
Not sure if this is a good plan. Might be best to wait until the rust-lang/rfcs#2115 is settled, since that would permit us to make a suggestion where we just add a fresh named lifetime, and we don't have to add <'a>
or anything.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.Working group: Diagnostics