Skip to content

E0495 shows the same found and expected #87109

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

Closed
MarkTanashchuk opened this issue Jul 13, 2021 · 2 comments
Closed

E0495 shows the same found and expected #87109

MarkTanashchuk opened this issue Jul 13, 2021 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@MarkTanashchuk
Copy link

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

@MarkTanashchuk MarkTanashchuk added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 13, 2021
@FabianWolff
Copy link
Contributor

Related to (or maybe a duplicate of) #73521.

@MarkTanashchuk
Copy link
Author

Related to (or maybe a duplicate of) #73521.

Yes, I think it would be better to close this issue in favor of #73521

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants