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

Suggest Explicit Lifetime for Associated Type Bindings #123245

Conversation

veera-sivarajan
Copy link
Contributor

Fixes #122025

This PR suggests an explicit lifetime annotation for associated type bindings. Previously, this error suggested an incorrect HRTB.

Please let me know if there's a better way to figure is_associated_type_binding. Also, this suggestion uses Applicability::MaybeIncorrect as the suggestion can be incorrect when a trait's input lifetimes are also missing.

@rustbot
Copy link
Collaborator

rustbot commented Mar 30, 2024

r? @cjgillot

rustbot has assigned @cjgillot.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 30, 2024
],
Applicability::MachineApplicable,
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is existing diagnostic code in rustc_resolve::late::diagnostics. We should adapt and reuse add_missing_lifetime_specifiers_label and suggest_introducing_lifetime.

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 6, 2024
@fmease
Copy link
Member

fmease commented Apr 10, 2024

CC #123713 (comment) (last paragraph). The “proper” way to fix #122025 is to stash the diagnostic in rustc_resolve::late and to try_steal_modify_and_emit_err it during HIR ty lowering where we have the necessary tools available to check if a lifetime param would be unconstrained (cc validate_late_bound_regions, collect_constrained_late_bound_regions). However that might not be feasible to implement, needs experimentation.

I've only glanced at the changes made in this PR but you seem to be taking the alternative approach that I've dubbed “heuristic in late” in my linked comment. That's perfectly valid, too. My linked comments might provide some more food for thought :)

@bors
Copy link
Contributor

bors commented Apr 15, 2024

☔ The latest upstream changes (presumably #123968) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@veera-sivarajan any updates on this? thanks

@veera-sivarajan
Copy link
Contributor Author

Still working on it. Thanks for checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing explicit lifetime in associated type suggests introducing invalid higher-ranked lifetime
6 participants