-
Notifications
You must be signed in to change notification settings - Fork 51
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
DbTxn must_use doesn't work #578
Comments
rust-lang/rust#102238 (comment) for my comment on the relevant issue. |
#[must_use]
trait X {}
fn y<Z: X>(z: Z) -> Z {
z
}
fn a<Z: X>(z: Z) {
y(z);
}
#[must_use]
struct A;
impl X for A {}
fn main() {
a(A);
} for the MRE. |
We can wrap the DbTxn generic in a struct which is must_use to workaround this. It's ugly but would be safe. |
must_use only requires use on a branch, not on all branches :/// |
The struct (and the correct application of must_use) would only guarantee the txn is bound, not moved out of scope. Opened an issue calling for a new clippy lint for an expanded interpretation of must_use: rust-lang/rust-clippy#13997 |
I did try the idea in rust-lang/rust-clippy#13997 (comment). While it is incomplete, I wanted to see if it was sufficiently complete for our use case. For the remaining edge cases, we could write The compiler will generate code to drop the txn if the txn is held across an await point (in case the future is dropped). We'd have to wrap the txn in a droppable struct before each await point, unwrapping it after. That'd be a notable ergonomic pain. We'd also have to move to |
coordinator/cosign/src/delay.rs literally demonstrates how we'd need to rewrite our handling of transactions with this change. It can be cleaned up a bit but already identifies ergonomic issues. It also doesn't model passing an &mut txn to an async function, which would also require using the droppable wrapper struct. To locally see this build, run RUSTFLAGS="-Zpanic_abort_tests -C panic=abort" cargo +nightly build -p serai-cosign --all-targets To locally see this fail to build, run cargo build -p serai-cosign --all-targets While it doesn't say which line causes it fail to build, the only distinction is panic=unwind. For more context, please see #578.
This is presumably somewhat a bug in Rust itself. I just need to make a MRE and evaluate it.
Identified due to #561.
The text was updated successfully, but these errors were encountered: