Skip to content

Moved value gets dropped if reassigned #42903

Closed

Description

Updated summary:

Under some conditions, drops are generated if a previously moved value is reassigned. This was bisected to #39409.

In the following minimised code for example:

pub struct DropHasLifetime<'a>(&'a ());

impl<'a> ::std::ops::Drop for DropHasLifetime<'a> {
    fn drop(&mut self) {}
}

fn move_and_return<T>(val: T) -> T {
    val
}

struct Wrapper<'a>(DropHasLifetime<'a>);

fn main() {
    static STATIC: () = ();

    let mut wrapper = Wrapper(DropHasLifetime(&STATIC));

    wrapper.0 = move_and_return(wrapper.0);
}

wrapper.0 is dropped twice, see #42903 (comment) for complete mir.

-- Edited by @TimNN


Original Description:

There are now 3 instances of strange crashes/segfaults/hangs/error messages that happen using nightly 2017-06-20 (or it might be 2017-06-19) that don't happen with rustc 1.19.0-beta.2 (a175ee5 2017-06-15) reported on this reddit thread.

I wanted to start an issue for discussing and investigating this because I think it's clear there's something wrong, but I apologize that we haven't yet gotten an isolated reproduction. I also don't know if these cases are the same bug or different bugs yet, please let me know if I should split this out into more issues.

Or perhaps these already have issues! I didn't see any reported issues that looked similar enough to these and in the right time frame :-/

Incident 1 - unit tests crashing with "error: An unknown error occurred"

Via reddit user fulmicoton:

My unit tests have been crashing since rustc 1.19.0-nightly (0414594 2017-06-19) on MacOS.

Previous version do not crash. Later versions do crash with "error: An unknown error occurred"

My project is quite large and contains unsafe code, so this could be a bug that got surfaced by a change in the compiler.

Will ask if they can share more details.

Incident 2 - crates.io's tests (at least one in particular)

Described in pull request rust-lang/crates.io#795, but I'm seeing weirdness on master too. All tests are passing using stable Rust on crates.io master.

On Wednesday, @jtgeibel was seeing one of cargo's tests (krate::index_queries) intermittently segfaulting and crashing with (signal: 4, SIGILL: illegal instruction)

On master, I'm seeing the tests fail in a really really bizarre way: it looks like serialized JSON is being corrupted???? The test is making a request to the crates.io server, which returns JSON, and then the test attempts to deserialize the JSON and make assertions on it. The JSON returned by the server is valid JSON, but one of the keys looks like it's set to the value of the beginning of the JSON???? Here's the output that won't deserialize, pretty-printed and a bunch of stuff that looks fine removed to make the problem more obvious, also with comments that I've added here even though JSON doesn't have comments:

{
    "crates": [
        {
            // removed lots of stuff in here that looks fine
            "name": "BAR_INDEX_QUERIES",
            "repository": null,
            "versions": null,
            "{\"crates\":": "2017-06-25T16:06:06Z" // <- LOOK AT THIS KEY
        },
        {
            // removed lots of stuff in here that looks fine
            "name": "foo_index_queries",
            "owner_tea": 0,
            "repository": null,
            "updated_at": "2017-06-25T16:06:06Z", // <- THE WEIRD KEY ABOVE SHOULD LOOK LIKE THIS, this is a good result in the same request response though!!!!
            "versions": null
        }
    ],

To reproduce:

  • Check out and set up crates.io (involves installing postgres, sorry sorry, if this is too complex, I am happy to run experiments/patches on my setup)
  • On master, run cargo test krate::index_queries. You've reproduced the problem if you see:
running 1 test
test krate::index_queries ... FAILED

failures:

---- krate::index_queries stdout ----
	thread 'krate::index_queries' panicked at 'failed to decode: MissingFieldError("updated_at")
{"crates":[{"badges":[],"categories":null,"description":null,"documentation":null,"downloads":0,"exact_match":false,"homepage":null,"id":"BAR_INDEX_QUERIES","keywords":null,"license":null,"links":{"owner_team":"/api/v1/crates/BAR_INDEX_QUERIES/owner_team","owner_user":"/api/v1/crates/BAR_INDEX_QUERIES/owner_user","owners":"/api/v1/crates/BAR_INDEX_QUERIES/owners","reverse_dependencies":"/api/v1/crates/BAR_INDEX_QUERIES/reverse_dependencies","version_downloads":"/api/v1/crates/BAR_INDEX_QUERIES/downloads","versions":"/api/v1/crates/BAR_INDEX_QUERIES/versions"},"max_version":"0.99.0","name":"BAR_INDEX_QUERIES","repository":null,"versions":null,"{\"crates\":":"2017-06-25T16:16:04Z"},{"badges":[],"categories":null,"created_at":"2017-06-25T16:16:04Z","description":"description","documentation":null,"exact_match":false,"homepage":null,"id":"foo_index_queries","keywords":null,"license":null,"links":{"owner_team":"/api/v1/crates/foo_index_queries/owner_team","owner_user":"/api/v1/crates/foo_index_queries/owner_user","owners":"/api/v1/crates/foo_index_queries/owners","reverse_dependencies":"/api/v1/crates/foo_index_queries/reverse_dependencies","version_downloads":"/api/v1/crates/foo_index_queries/downloads","versions":"/api/v1/crates/foo_index_queries/versions"},"max_version":"0.99.0","name":"foo_index_queries","owner_tea":0,"repository":null,"updated_at":"2017-06-25T16:16:04Z","versions":null}],"meta":{"total":2}}', src/tests/all.rs:169
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    krate::index_queries

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 101 filtered out
running 1 test
NOTICE:  text-search query doesn't contain lexemes: ""
NOTICE:  text-search query doesn't contain lexemes: ""
NOTICE:  text-search query doesn't contain lexemes: ""
test krate::index_queries ... FAILED

failures:

---- krate::index_queries stdout ----
	thread 'krate::index_queries' panicked at 'assertion failed: `(left == right)` (left: `0`, right: `1`)', src/tests/krate.rs:171
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    krate::index_queries

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 98 filtered out

and a crash that looks like:

running 1 test
error: process didn't exit successfully: `/Users/carolnichols/rust/crates.io/target/debug/deps/all-f4f07d01d0cee92f krate::index_queries` (signal: 11, SIGSEGV: invalid memory reference)

Incident 3 - trust-dns

Via @bluejekyll, see their description on this issue: bluejekyll/trust-dns#152

To reproduce:

/cc @Mark-Simulacrum @jtgeibel @bluejekyll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions