-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 adding a new lifetime parameter when two elided lifetimes should match up for traits and impls. #94464
Suggest adding a new lifetime parameter when two elided lifetimes should match up for traits and impls. #94464
Conversation
…uld match up for traits and impls. Issue rust-lang#94462
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm +1 on the code changes, but would you mind taking a look at my wording nitpick?
.. | ||
}) | ||
| hir::Node::TraitItem(&hir::TraitItem { ref generics, .. }) | ||
| hir::Node::ImplItem(&hir::ImplItem { ref generics, .. }) => generics, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should handle the impl
case specifically with extra wording in the suggestion to let people know that they'll have to modify the trait
as well. This is likely not a problem in practice, but I'd like us to be thorough and avoid confusing people.
It might be enough to just have a boolean flag that you use to modify the suggestion description with extra wording.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I'll make that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this for impl
?
help: consider introducing a named lifetime parameter and update trait if needed
|
32 | fn foo<'a>(&'a self, x: &i32, z: &'a i32) -> Option<&i32> {
| ++++ ++ ++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0623`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we would have something like "consider introducing a named lifetime parameter and update trait TraitName
as necessary", by getting the TraitName
from the parent DefId, but that can be left as follow up work.
help: consider introducing a named lifetime parameter | ||
| | ||
LL | fn a<'a>(self: Pin<&'a Foo>, f: &'a Foo) -> &Foo { f } | ||
| ++++ ++ ++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat surprised by the suggestions I'm seeing that we don't also suggest adding 'a
to the return type. Maybe an existing bug? No need to handle it in this case directly, but would we should make a note of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to add a comment about that note?
I'm not 100% sure it's a bug. Seems like the code that added the hint did not take into consideration return types. To be fair though, AFAICT the diagnosis in this module is implemented very differently than what is in LifetimeContext
in add_missing_lifetime_specifiers_label (which does add lifetime hints for the return type). LifetimeContext
has a lot more "information", which it gathers during compilation, about the error so it can construct a better hint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just create a targeted ticket for this instead of leaving it in the code. It'd be p-low
, as we already have follow up suggestions to get you to working code, although it isn't great when there's another lifetime involved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bors r+ |
📌 Commit 1b08cba has been approved by |
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#94464 (Suggest adding a new lifetime parameter when two elided lifetimes should match up for traits and impls.) - rust-lang#94476 (7 - Make more use of `let_chains`) - rust-lang#94478 (Fix panic when handling intra doc links generated from macro) - rust-lang#94482 (compiler: fix some typos) - rust-lang#94490 (Update books) - rust-lang#94496 (tests: accept llvm intrinsic in align-checking test) - rust-lang#94498 (9 - Make more use of `let_chains`) - rust-lang#94503 (Provide C FFI types via core::ffi, not just in std) - rust-lang#94513 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Closes #94462 |
Suggest adding a new lifetime parameter when two elided lifetimes should match up for functions in traits and impls.
Issue #94462