On borrow return type, suggest borrowing from arg or owned return type#117914
Merged
bors merged 9 commits intorust-lang:masterfrom Dec 12, 2023
Merged
On borrow return type, suggest borrowing from arg or owned return type#117914bors merged 9 commits intorust-lang:masterfrom
bors merged 9 commits intorust-lang:masterfrom
Conversation
Collaborator
|
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
Collaborator
|
☔ 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
wesleywiser
reviewed
Nov 22, 2023
Comment on lines
+2957
to
+2958
| ", but this is uncommon unless you're returning a borrowed value from a \ | ||
| `const` or a `static`{owned}", |
Member
There was a problem hiding this comment.
Should we make these messages translatable?
Contributor
Author
There was a problem hiding this comment.
We should, but I didn't want to make the PR too big to review.
wesleywiser
approved these changes
Dec 12, 2023
Member
|
@bors r+ |
Collaborator
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Dec 12, 2023
…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
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Dec 12, 2023
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the
'staticlifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type.Fix #85843.