-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
On borrow return type, suggest borrowing from arg or owned return type #117914
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
bc34aa4
to
1afef41
Compare
This comment was marked as resolved.
This comment was marked as resolved.
61bc7d1
to
3e26c52
Compare
☔ The latest upstream changes (presumably #117683) made this pull request unmergeable. Please resolve the merge conflicts. |
When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the `'static` lifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type. ``` error[E0106]: missing lifetime specifier --> $DIR/variadic-ffi-6.rs:7:6 | LL | ) -> &usize { | ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | LL | ) -> &'static usize { | +++++++ help: instead, you are more likely to want to change one of the arguments to be borrowed... | LL | x: &usize, | + help: ...or alternatively, to want to return an owned value | LL - ) -> &usize { LL + ) -> usize { | ``` Fix rust-lang#85843.
When encountering ```rust fn g(mut x: impl Iterator<Item = &()>) -> Option<&()> { /* */ } ``` Suggest ```rust fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { /* */ } ```
3e26c52
to
eee4cc6
Compare
", but this is uncommon unless you're returning a borrowed value from a \ | ||
`const` or a `static`{owned}", |
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.
Should we make these messages translatable?
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, but I didn't want to make the PR too big to review.
@bors r+ |
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#116740 (dont ICE when ConstKind::Expr for is_const_evaluatable) - rust-lang#117914 (On borrow return type, suggest borrowing from arg or owned return type) - rust-lang#117927 (Clarify how to choose a FutureIncompatibilityReason variant.) - rust-lang#118855 (Improve an error involving attribute values.) - rust-lang#118856 (rustdoc-search: clean up parser) - rust-lang#118865 (rustc_codegen_llvm: Enforce `rustc::potential_query_instability` lint) - rust-lang#118866 (llvm-wrapper: adapt for LLVM API change) - rust-lang#118868 (Correctly gate the parsing of match arms without body) - rust-lang#118877 (tests: CGU tests require build-pass, not check-pass (remove FIXME)) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#117914 - estebank:issue-85843, r=wesleywiser On borrow return type, suggest borrowing from arg or owned return type When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the `'static` lifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type. ``` error[E0106]: missing lifetime specifier --> $DIR/variadic-ffi-6.rs:7:6 | LL | ) -> &usize { | ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | LL | ) -> &'static usize { | +++++++ help: instead, you are more likely to want to change one of the arguments to be borrowed... | LL | x: &usize, | + help: ...or alternatively, to want to return an owned value | LL - ) -> &usize { LL + ) -> usize { | ``` Fix rust-lang#85843.
When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the
'static
lifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type.Fix #85843.