rust/tests/ui/lifetimes/mut-ref-owned-suggestion.stderr
reddevilmidzy e0d9d470df Fix invalid mut T suggestion for &mut T in missing lifetime error
* Find ref prefix span for owned suggestions
* Improve missing lifetime suggestions for `&mut str`
2026-02-17 10:18:08 +00:00

137 lines
6 KiB
Text

error[E0106]: missing lifetime specifier
--> $DIR/mut-ref-owned-suggestion.rs:4:29
|
LL | fn with_fn(_f: impl Fn() -> &mut ()) {}
| ^ 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 | fn with_fn(_f: impl Fn() -> &'static mut ()) {}
| +++++++
help: instead, you are more likely to want to return an owned value
|
LL - fn with_fn(_f: impl Fn() -> &mut ()) {}
LL + fn with_fn(_f: impl Fn() -> ()) {}
|
error[E0106]: missing lifetime specifier
--> $DIR/mut-ref-owned-suggestion.rs:7:38
|
LL | fn with_ref_mut_str(_f: impl Fn() -> &mut str) {}
| ^ 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 | fn with_ref_mut_str(_f: impl Fn() -> &'static mut str) {}
| +++++++
help: instead, you are more likely to want to return an owned value
|
LL - fn with_ref_mut_str(_f: impl Fn() -> &mut str) {}
LL + fn with_ref_mut_str(_f: impl Fn() -> String) {}
|
error[E0106]: missing lifetime specifier
--> $DIR/mut-ref-owned-suggestion.rs:10:40
|
LL | fn with_fn_has_return(_f: impl Fn() -> &mut ()) -> i32 {
| ^ 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
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
|
LL | fn with_fn_has_return(_f: impl Fn() -> &'static mut ()) -> i32 {
| +++++++
help: consider making the bound lifetime-generic with a new `'a` lifetime
|
LL - fn with_fn_has_return(_f: impl Fn() -> &mut ()) -> i32 {
LL + fn with_fn_has_return(_f: impl for<'a> Fn() -> &'a ()) -> i32 {
|
help: consider introducing a named lifetime parameter
|
LL - fn with_fn_has_return(_f: impl Fn() -> &mut ()) -> i32 {
LL + fn with_fn_has_return<'a>(_f: impl Fn() -> &'a ()) -> i32 {
|
help: alternatively, you might want to return an owned value
|
LL - fn with_fn_has_return(_f: impl Fn() -> &mut ()) -> i32 {
LL + fn with_fn_has_return(_f: impl Fn() -> ()) -> i32 {
|
error[E0106]: missing lifetime specifier
--> $DIR/mut-ref-owned-suggestion.rs:15:33
|
LL | fn with_dyn(_f: Box<dyn Fn() -> &mut i32>) {}
| ^ 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 | fn with_dyn(_f: Box<dyn Fn() -> &'static mut i32>) {}
| +++++++
help: instead, you are more likely to want to return an owned value
|
LL - fn with_dyn(_f: Box<dyn Fn() -> &mut i32>) {}
LL + fn with_dyn(_f: Box<dyn Fn() -> i32>) {}
|
error[E0106]: missing lifetime specifier
--> $DIR/mut-ref-owned-suggestion.rs:18:27
|
LL | fn trait_bound<F: Fn() -> &mut i32>(_f: F) {}
| ^ 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 | fn trait_bound<F: Fn() -> &'static mut i32>(_f: F) {}
| +++++++
help: instead, you are more likely to want to change the argument to be borrowed...
|
LL | fn trait_bound<F: Fn() -> &mut i32>(_f: &F) {}
| +
help: ...or alternatively, you might want to return an owned value
|
LL - fn trait_bound<F: Fn() -> &mut i32>(_f: F) {}
LL + fn trait_bound<F: Fn() -> i32>(_f: F) {}
|
error[E0106]: missing lifetime specifier
--> $DIR/mut-ref-owned-suggestion.rs:21:42
|
LL | fn nested_result(_f: impl Fn() -> Result<&mut i32, ()>) {}
| ^ 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 | fn nested_result(_f: impl Fn() -> Result<&'static mut i32, ()>) {}
| +++++++
help: instead, you are more likely to want to return an owned value
|
LL - fn nested_result(_f: impl Fn() -> Result<&mut i32, ()>) {}
LL + fn nested_result(_f: impl Fn() -> Result<i32, ()>) {}
|
error[E0106]: missing lifetime specifier
--> $DIR/mut-ref-owned-suggestion.rs:24:26
|
LL | struct Holder<F: Fn() -> &mut i32> {
| ^ 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 | struct Holder<F: Fn() -> &'static mut i32> {
| +++++++
help: instead, you are more likely to want to return an owned value
|
LL - struct Holder<F: Fn() -> &mut i32> {
LL + struct Holder<F: Fn() -> i32> {
|
error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0106`.