-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Confusing lifetime error: expected (&Location<'_>,)
, found (&Location<'_>,)
#79033
Comments
I marked this as a regression since the error has gotten worse since stable and beta. |
This looks like another duplicate of #41078. |
Adding type annotations to the closure doesn't fix it though: #[derive(Debug, Clone, Copy)]
pub struct Location<'a> {
pub filename: &'a str,
pub start: LocationHalf,
pub end: LocationHalf,
}
#[derive(Debug, Clone, Copy)]
pub struct LocationHalf {
pub line: u32,
pub column: u32,
}
impl Location<'_> {
/// Returns an iterator over the line numbers of this location.
pub fn line_numbers(self) -> impl Iterator<Item = u32> {
self.start.line..=self.end.line
}
/// Returns an iterator over the line numbers and lines of this location.
pub fn lines<'a>(self, source: &'a str) -> impl Iterator<Item = (u32, &'a str)> {
let lines = source.split('\n');
lines.enumerate().filter_map(|(i, line): (usize, &'a str)| {
if self.start.line as usize <= i && i <= self.end.line as usize {
Some((i as u32 + 1, line))
} else {
None
}
})
}
} Errors:
|
Also, notice that the error note shows tuples on nightly but not stable – that seems like a bug. And, why does the error say:
I don't understand why it must match the |
Here is a fixed version: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=3d9156ed9de67e4bf402f54243f5f3e8 So the error is correct, it's just confusing. |
Assigning |
I still don't really understand why this code doesn't work, but the confusing error should be fixed by #73521. |
For one, I'm not sure why this isn't working since
Location
isCopy
, but you can fix this by just storingself.start.line
andself.end.line
in locals and addingmove
before the closure. One of the weird things about this error is it saysbut those are the same! Also, why are they 1-tuples? The error is a bit different on stable, the message I showed is on nightly:
Code
(Playground)
Errors:
The text was updated successfully, but these errors were encountered: