-
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
Merged
Commits on Nov 20, 2023
-
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.
Configuration menu - View commit details
-
Copy full SHA for b7a23bc - Browse repository at this point
Copy the full SHA b7a23bcView commit details -
Account for impl Trait in lifetime suggestion
When encountering ```rust fn g(mut x: impl Iterator<Item = &()>) -> Option<&()> { /* */ } ``` Suggest ```rust fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { /* */ } ```
Configuration menu - View commit details
-
Copy full SHA for 5fce361 - Browse repository at this point
Copy the full SHA 5fce361View commit details -
Configuration menu - View commit details
-
Copy full SHA for d30252e - Browse repository at this point
Copy the full SHA d30252eView commit details -
Configuration menu - View commit details
-
Copy full SHA for dec7f00 - Browse repository at this point
Copy the full SHA dec7f00View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2a92d82 - Browse repository at this point
Copy the full SHA 2a92d82View commit details -
Configuration menu - View commit details
-
Copy full SHA for 85f26ad - Browse repository at this point
Copy the full SHA 85f26adView commit details -
Configuration menu - View commit details
-
Copy full SHA for bb9d720 - Browse repository at this point
Copy the full SHA bb9d720View commit details -
Configuration menu - View commit details
-
Copy full SHA for 02bea16 - Browse repository at this point
Copy the full SHA 02bea16View commit details -
Configuration menu - View commit details
-
Copy full SHA for eee4cc6 - Browse repository at this point
Copy the full SHA eee4cc6View commit details
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.