Closed
Description
Given the following code, the current output in Rust Analyzer is:
cannot infer an appropriate lifetime for autoref due to conflicting requirements
expected `std::str::Chars<'_>`
found `std::str::Chars<'_>`(rustc E0495)
lib.rs(6, 20): first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 6:20...
lib.rs(8, 20): ...so that reference does not outlive borrowed content
lib.rs(5, 16): but, the lifetime must be valid for the lifetime `'_` as defined on the impl at 5:16...
lib.rs(8, 20): ...so that the expression is assignable
And in the playground:
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
--> src/main.rs:8:27
|
8 | chars: source.chars()
| ^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 6:20...
--> src/main.rs:6:20
|
6 | fn new(source: &str) -> Self {
| ^^^^
note: ...so that reference does not outlive borrowed content
--> src/main.rs:8:20
|
8 | chars: source.chars()
| ^^^^^^
note: but, the lifetime must be valid for the lifetime `'_` as defined on the impl at 5:16...
--> src/main.rs:5:16
|
5 | impl SomeChars<'_> {
| ^^
note: ...so that the expression is assignable
--> src/main.rs:8:20
|
8 | chars: source.chars()
| ^^^^^^^^^^^^^^
= note: expected `Chars<'_>`
found `Chars<'_>`
I think it would be helpful to add a tip that brings the code to something like in this playground and, if possible, make the Chars<'_> in 'found'/'expected' different