-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Random lifetime may not live long enough
from other part of the code
#96645
Comments
Could be closed immediately if not of value. |
This has also been happening to me on recent nightlies (for the past week or two). Unfortunately, it does sound like a hard to repro bug. I have found this problem happens much more in rust-analyzer than in command line compiles, not sure if that means anything though. As a workaround, I am doing a clean rebuild. |
This is now happening constantly for me (almost every build). Unfortunately, I don't have a repro. It does seem to be somehow related to rust-analyzer though (very low confidence for this). |
I don't use rust-analyzer, so it's probably not the origin. Though I didn't have any more problems so far. |
I also had this happen though I haven't been able to reproduce it either. As far as I can tell it's related to async functions since I haven't seen it occur in any other case. Specifying lifetime bounds manually seems to help though. |
Seeing something similar in our closed-source module. The beta compiler (1.62.0-beta.4) suddenly started rejecting some sqlx code which looks like this (details omitted): #[derive(Debug, sqlx::FromRow)]
struct Grid {
id: i64,
row: f32,
};
struct Target {
id: i64,
grid_id: Option<i64>,
...
}
/// Just for namespacing
struct GridSql;
impl GridSql {
pub async fn add_empty<'t>(
target: &Target,
mut tx: sqlx::Transaction<'t, Postgres>,
) -> sqlx::Result<sqlx::Transaction<'t, Postgres>> {
let grid_id = sqlx::query_as!(
Grid,
r#"
INSERT INTO grid (
row
) VALUES($1)
RETURNING
id, ...
"#,
0.0,
)
.fetch_one(&mut tx)
.await?
.id;
sqlx::query!(
"UPDATE target SET grid_id = $1 WHERE id = $2",
grid_id,
target.id,
)
.execute(&mut tx)
.await?;
Ok(tx)
}
} The error message is:
This does not happen on stable. Unfortunately, pulling the code out of the codebase verbatim did not give an error, so creating a reproducible example seems very hard again. |
Hopefully, it has nothing to do with switching to the MIR borrow checker 😬. As far as I know, the plan is to stabilise it in August. Since @Edgeworth and I first noticed the bug on nightly, and it now propagated to beta this might be the case. I have no idea when the NLL borrow checking was merged though, so it might be something different. |
@rustbot label +A-NLL +NLL-complete |
By the way, I just found a breaking case for this even in the explicitly specified lifetimes case. Originally, I had this, which sometimes produced the error message in the original post. The frequency of this error decreased after I changed it to this signature:
However, I just got this error recently:
Note that there is no reason for 'b to have to outlive 'a in my actual code (and indeed, it almost always compiles without issue). |
Looks like one of the new error messages of the NLL borrow checker: https://jackh726.github.io/rust/2022/06/10/nll-stabilization.html |
For what it's worth, I haven't seen this since upgrading to the 1.63 beta. |
I had this problem as well. I updated to 1.64 and the problem didn't occur when building clean. |
Now I got the problem on 1.64 after a few builds, clean builds help but they take forever |
Nominating for @rust-lang/compiler discussion because it seems like a latent bug or regression in incr-comp with nll borrowck. |
lifetime may not life long enought
from other part of the codelifetime may not live long enough
from other part of the code
I found a way to reliably reproduce the error locally (win 10). It, unfortunately, does not work in WSL or docker 😐. It's more or less a fuzzer, that generates random code from all the examples that were posted in this thread. It also sets up the exact same toolchain situation as on my local machine at the time I encountered the error (default: To run it, just execute Since I cannot reproduce it in WSL or docker, I included 5 Hopefully, that helps :) If I should run any other command locally, or I should share other files, I can do so. |
Cannot reproduce it with the latest stable/nightly on my machine |
I feel there are multiple issues at play here, due to the multiple lifetime resolution on AST & incremental compilation issues, whose introduction and fixes spanned a release. Some of these examples look similar to #98890, which matches that timeline:
Some also look coincidentally fixed by #97415 a few weeks beforehand (e.g. if you simply compile module B and then concat D, that reproduces the issue but the PR fixes that) Some commenters mention having the issue on 1.64.0 nightlies but we don't have reproductions for those yet. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
I just stumbled across a weird and inconsistent behaviour, that seems unreasonable to me.
The project I'm working on is a big company project (closed source) with quite some files. While fixing a bug and editing one line in one module (
src/dispatcher/compiler/module_range.rs
) the compiler suddenly decided to reject the code of a function from a completely different module (src/services/module_state_service.rs
) that has absolutely nothing to do with the module I'm working on.The change that I made:
The compiler error:
The function the compiler complains about:
When undoing the one-line change, the code compiled fine again, and after redoing it, it failed to compile again.
Now, after indenting a few pieces of code, to make pasting them into GitHub easier, the compiler again accepts the code.
I'm also no longer able to recreate the error.
I know, that's essentially nothing to work with, and I'm not even able to recreate the issue myself anymore, but it seems worth reporting to me.
The text was updated successfully, but these errors were encountered: