rust/tests/ui/lifetimes
Matthias Krüger ffdb471872
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.
2023-12-12 17:40:53 +01:00
..
auxiliary
lifetime-errors Add print_trait_sugared 2023-12-05 17:15:46 +00:00
anonymize-unnamed-bound-vars-in-binders.rs
bare-trait-object-borrowck.rs
bare-trait-object.rs
borrowck-let-suggestion.rs
borrowck-let-suggestion.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
conflicting-bounds.rs
conflicting-bounds.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
copy_modulo_regions.rs
copy_modulo_regions.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
elided-lifetime-in-anon-const.rs
elided-lifetime-in-param-pat.rs
elided-lifetime-in-path-in-impl-Fn.rs
elided-lifetime-in-path-in-pat.rs
elided-lifetime-in-path-in-type-relative-expression.rs
fullwidth-ampersand.rs
fullwidth-ampersand.stderr
issue-17728.rs
issue-17728.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-26638.rs
issue-26638.stderr Tweak wording 2023-11-20 23:44:37 +00:00
issue-34979.rs
issue-34979.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-36744-without-calls.rs
issue-54378.rs
issue-55796.rs
issue-55796.stderr
issue-64173-unused-lifetimes.rs
issue-64173-unused-lifetimes.stderr generic_const_exprs: suggest to add the feature, not use it 2023-11-30 20:59:51 +01:00
issue-67498.rs
issue-69314.fixed
issue-69314.rs
issue-69314.stderr
issue-70917-lifetimes-in-fn-def.rs
issue-76168-hr-outlives-2.rs
issue-76168-hr-outlives-3.rs Pretty print Fn traits in rustc_on_unimplemented 2023-11-02 20:57:05 +00:00
issue-76168-hr-outlives-3.stderr Pretty print Fn traits in rustc_on_unimplemented 2023-11-02 20:57:05 +00:00
issue-76168-hr-outlives.rs
issue-77175.rs s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
issue-79187-2.rs
issue-79187-2.stderr recurse into refs when comparing tys for diagnostics 2023-12-07 23:00:46 -05:00
issue-79187.rs
issue-79187.stderr Add print_trait_sugared 2023-12-05 17:15:46 +00:00
issue-83737-binders-across-types.rs
issue-83737-erasing-bound-vars.rs
issue-83753-invalid-associated-type-supertrait-hrtb.rs
issue-83753-invalid-associated-type-supertrait-hrtb.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-83907-invalid-fn-like-path.rs
issue-83907-invalid-fn-like-path.stderr
issue-84398.rs
issue-84604.rs
issue-90170-elision-mismatch.fixed
issue-90170-elision-mismatch.rs
issue-90170-elision-mismatch.stderr
issue-90600-expected-return-static-indirect.rs
issue-90600-expected-return-static-indirect.stderr
issue-91763.rs
issue-91763.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-93911.rs
issue-95023.rs
issue-95023.stderr
issue-97193.rs
issue-97193.stderr
issue-97194.rs
issue-97194.stderr
issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.fixed
issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs
issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-104432-unused-lifetimes-in-expansion.rs
issue-105227.fixed
issue-105227.rs
issue-105227.stderr
issue-105507.fixed
issue-105507.rs
issue-105507.stderr
issue-105675.rs
issue-105675.stderr Add print_trait_sugared 2023-12-05 17:15:46 +00:00
issue-107492-default-value-for-lifetime.rs
issue-107492-default-value-for-lifetime.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-107988.rs
issue-107988.stderr
lifetime-bound-will-change-warning.rs
lifetime-bound-will-change-warning.stderr
lifetime-doesnt-live-long-enough.rs
lifetime-doesnt-live-long-enough.stderr remove trailing dots 2023-10-08 10:06:17 +00:00
lifetime-elision-return-type-requires-explicit-lifetime.rs
lifetime-elision-return-type-requires-explicit-lifetime.stderr Fix incorrect lifetime suggestion 2023-11-20 23:44:37 +00:00
lifetime-elision-return-type-trait.rs
lifetime-elision-return-type-trait.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
lifetime-mismatch-between-trait-and-impl.rs
lifetime-mismatch-between-trait-and-impl.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
lifetime-no-keyword.rs
lifetime-no-keyword.stderr
missing-lifetime-in-alias.rs
missing-lifetime-in-alias.stderr
nested-binder-print.rs
nested-binder-print.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
nested.rs
re-empty-in-error.rs
re-empty-in-error.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
shadow.rs
shadow.stderr
suggest-introducing-and-adding-missing-lifetime.fixed
suggest-introducing-and-adding-missing-lifetime.rs
suggest-introducing-and-adding-missing-lifetime.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
undeclared-lifetime-used-in-debug-macro-issue-70152.rs
undeclared-lifetime-used-in-debug-macro-issue-70152.stderr
unnamed-closure-doesnt-life-long-enough-issue-67634.rs
unnamed-closure-doesnt-life-long-enough-issue-67634.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
unusual-rib-combinations.rs
unusual-rib-combinations.stderr