-
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
Pattern-destructing a struct inside a ~-pointer violates linearity #3224
Comments
More minimal:
|
related is the bicentordinally-older bug, #3024. |
Never mind my earlier comment; it was so wrong that I deleted it. |
There are two reasons this is happening:
If I recall correctly, we were going to get rid of |
Actually, fixing the code to make this work seems like more trouble than it's worth. I'm just going to remove |
I kinda feel like it's important to be able to move out of unique boxes when deallocating them. The only alternative is the option dance, which changes your datatypes everywhere else too, uses extra memory, etc. One use case is in |
...I don't think any of the three possible solutions would prevent moving out of unique boxes when deallocating? Unless I'm missing something. (Getting rid of |
Oh okay yeah. I've been thinking of |
Heh, re-reading the whole thing, I suspect getting rid of |
Indeed, the following code still shows the bug:
Fixing this will be part of #3271 -- the problem is right now, the binding of |
I thnk this has nothing to do with being a copy binding or not. If a struct has a destructor, you should not be able to move it into a destructuring pattern! |
What's wrong with moving a struct with a destructor into a destructuring pattern if the pattern is a by-ref binding? |
Even if there's not a by-ref binding, it should still be legal as long as the struct itself isn't being taken apart. The point is to write |
Ah, @bblum is correct, I was not being careful in my reading of the example. You should be able to move out of the I suppose @catamorphism that you are correct, we could allow you to move and then take a ref binding. This is sort of moving the value into a temporary, taking a ref into the temporary, and then letting the temp get cleaned up. Anyway, this gets to the matter of rvalue lifetimes, which I realize I should have also put on the 0.5 priorities. Bah. |
I attempted to transcribe the example into modern syntax, but we have gotten rid of struct A { x: &'self mut int }
struct B { x: A<'self> }
impl Drop for A<'self> {
fn finalize(&self) {
*(self.x) -= 1; error!("A");
}
}
fn main() {
let mut y = 3;
let bp = ~B { x: A { x: &mut y } };
let ~B { x: _a } = bp;
fail_unless!(y == 2);
} Note that I am not certain that this faithfully captures the original intent of the test (it does indeed fail, and then it also calls the finalizer twice). In any case, I am pretty sure this issue will not be resolved for 0.6 release. |
@lifthrasiir posted a snippet to #rust where an irrefutable &-pattern (originally in a closure parameter) caused a non-copyable value to be silently copied (... originally causing an SDL surface to be destroyed early). It reduces to something like
which runs the finalizer twice with different output. Is that the same issue? Note that with |
I think this is serious but on the same level as other linearity bugs -- not fixable in the 0.6 timeframe and not so user-facing or semantics-effecting that it requires attention above the others. De-milestoning. |
@catamorphism and @nikomatsakis: I'm debating about nominating this for a maturity milestone. In particular, the fact that there has been:
has made me wonder if this is a candidate for "Maturity Milestone 1: well defined", in the sense that we should specify the interactions of moves/linearity and finalization (that's milestone 1), and write a stable regression test for this example (which might more appropriately belong with milestone 2: backwards compatible). But I thought I would bring the topic up here first, rather than waiting until the triage meeting and potentially bogging it down for more minutes than this issue warrants. |
@pnkfelix I think this belongs in milestone 1, too. |
I'll write up a post on how I think it ought to work. |
(I don't really feel there is any doubt) |
In particular we already agreed to #4384 which is a generalization of the questions raised here. |
accepted for backwards-compatible milestone |
sub-bug of #3235 |
Updated version in all `Cargo.toml` files (via `find . -name Cargo.toml -exec sed -i 's/version = "0.51.0"/version = "0.52.0"/' {} \;`) and ran `cargo build-dev` to have `Cargo.lock` files updated. GitHub generated release notes: ## What's Changed * Bump tests/perf/s2n-quic from `6dd41e0` to `bd37960` by @dependabot in model-checking/kani#3178 * Automatic cargo update to 2024-05-13 by @github-actions in model-checking/kani#3177 * Upgrade toolchain to 2024-04-22 by @zhassan-aws in model-checking/kani#3171 * Upgrade toolchain to 2024-05-14 by @zhassan-aws in model-checking/kani#3183 * Automatic toolchain upgrade to nightly-2024-05-15 by @github-actions in model-checking/kani#3185 * Include `--check-cfg=cfg(kani)` in the rust flags to avoid a warning about an unknown `cfg`. by @zhassan-aws in model-checking/kani#3187 * Automatic toolchain upgrade to nightly-2024-05-16 by @github-actions in model-checking/kani#3189 * Perform cargo update because of yanked libc version by @zhassan-aws in model-checking/kani#3192 * Automatic toolchain upgrade to nightly-2024-05-17 by @github-actions in model-checking/kani#3191 * Automatic cargo update to 2024-05-20 by @github-actions in model-checking/kani#3195 * Bump tests/perf/s2n-quic from `bd37960` to `f5d9d74` by @dependabot in model-checking/kani#3196 * New section about linter configuraton checking in the doc. by @remi-delmas-3000 in model-checking/kani#3198 * Automatic cargo update to 2024-05-27 by @github-actions in model-checking/kani#3201 * Bump tests/perf/s2n-quic from `f5d9d74` to `d03cc47` by @dependabot in model-checking/kani#3202 * Update Rust toolchain from nightly-2024-05-17 to nightly-2024-05-23 by @remi-delmas-3000 in model-checking/kani#3199 * Fix `{,e}println!()` by @GrigorenkoPV in model-checking/kani#3209 * Contracts for a few core functions by @celinval in model-checking/kani#3107 * Don't crash benchcomp when rounding non-numeric values by @karkhaz in model-checking/kani#3211 * Update Rust toolchain nightly-2024-05-24 by @qinheping in model-checking/kani#3212 * Upgrade Rust toolchain nightly-2024-05-27 by @qinheping in model-checking/kani#3215 * Automatic toolchain upgrade to nightly-2024-05-28 by @github-actions in model-checking/kani#3217 * Automatic cargo update to 2024-06-03 by @github-actions in model-checking/kani#3220 * Bump tests/perf/s2n-quic from `d03cc47` to `d90729d` by @dependabot in model-checking/kani#3222 * Add simple API for shadow memory by @zhassan-aws in model-checking/kani#3200 ## New Contributors * @GrigorenkoPV made their first contribution in model-checking/kani#3209 **Full Changelog**: model-checking/kani@kani-0.51.0...kani-0.52.0
EDIT(bblum): modernized the example
This runs the destructor twice and crashes. It does not run the destructor twice if the
~
are removed.Unlike #3218, this code should compile, because A is the one with the destructor.
The text was updated successfully, but these errors were encountered: