diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-12-12 17:40:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-12 17:40:53 +0100 |
| commit | ffdb471872efb9c7f74c0ea039c9206609c8bf39 (patch) | |
| tree | fbf9c437a29fc4bbf6861c548dea8abd0df74ba5 /tests/ui/underscore-lifetime | |
| parent | b2a0175b97195e5ac722445e5196379e891341d0 (diff) | |
| parent | eee4cc661677be3bf58db12ea1ee598e822762ff (diff) | |
| download | rust-ffdb471872efb9c7f74c0ea039c9206609c8bf39.tar.gz rust-ffdb471872efb9c7f74c0ea039c9206609c8bf39.zip | |
Rollup merge of #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 #85843.
Diffstat (limited to 'tests/ui/underscore-lifetime')
| -rw-r--r-- | tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr b/tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr index 50401791eff..cd74d27dcb5 100644 --- a/tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr +++ b/tests/ui/underscore-lifetime/underscore-lifetime-binders.stderr @@ -28,7 +28,7 @@ LL | fn meh() -> Box<dyn for<'_> Meh<'_>> | ^^ 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 +help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`, or if you will only have owned values | LL | fn meh() -> Box<dyn for<'_> Meh<'static>> | ~~~~~~~ |
