Skip to content
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

Segfault when calling a method on an owned box cast to a trait and passed to another task #5882

Closed
mzabaluev opened this issue Apr 14, 2013 · 3 comments

Comments

@mzabaluev
Copy link
Contributor

This program compiles successfully, but segfaults:

trait A {
    fn f(&self);
}

struct B;

impl A for B {
    fn f(&self) {
    }
}

fn main() {
    let a = ~B as ~A;
    do spawn {
        a.f();
    }
}

The crash occurs in a generated thunk opaque to gdb:

#0  0x080494cb in glue_drop_2597 ()
#1  0x08048bc4 in main () at unsafe-owned.rs:15
#2  0x08048c10 in _rust_main () at unsafe-owned.rs:15
#3  0xb7495d01 in task_start_wrapper (a=0x9c4663c)
    at /home/mzabaluev/src/rust/src/rt/rust_task.cpp:162
@alexcrichton
Copy link
Member

Nominating for production-ready.

This code today actually produces an LLVM assertion as well:

Assertion failed: (Ty && "Invalid GetElementPtrInst indices for type!"), function checkGEPType, file /Users/alex/code/rust-opt/src/llvm/include/llvm/IR/Instructions.h, line 704.
zsh: abort      rust run foo.rs

@huonw
Copy link
Member

huonw commented Jun 2, 2013

This fails with the same error with 63417da (but I don't think it fails with 803c12d):

trait A {}
fn main() {
  let a: ~[~A] = ~[];
}

@Aatch
Copy link
Contributor

Aatch commented Jun 2, 2013

This is actually more general, with the assertion happening on pretty much any instance of an owned trait object.

I would suggest this be feature-complete, since trait objects are a feature, and clearly this is not complete.

bors added a commit that referenced this issue Jun 22, 2013
This finishes the incomplete conversion of unique traits as two-word
allocations started in 211d038.

Fixes #5882, #6717, #7153, #7208.
@bors bors closed this as completed in de471a2 Jun 22, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 11, 2020
… r=Manishearth

Prevent compile parts of rustc when using `cargo dev ra-setup`

Currently after running `cargo dev ra-setup` the following lines are added to `Cargo.toml`:

```toml
[target]
rustc_data_structures = { path = ".../rust/src/librustc_data_structures" }
rustc_driver = { path = ".../rust/src/librustc_driver" }
rustc_errors = { path = ".../rust/src/librustc_errors" }
rustc_interface = { path = ".../rust/src/librustc_interface" }
rustc_middle = { path = ".../rust/src/librustc_middle" }
```

This pull request adds dependencies for `rustc` crates under `cfg(NOT_A_PLATFORM)`, thus preventing them from compiling together with clippy:

```toml
[target.'cfg(NOT_A_PLATFORM)'.dependencies]
rustc_data_structures = { path = ".../rust/src/librustc_data_structures" }
rustc_driver = { path = ".../rust/src/librustc_driver" }
rustc_errors = { path = ".../rust/src/librustc_errors" }
rustc_interface = { path = ".../rust/src/librustc_interface" }
rustc_middle = { path = ".../rust/src/librustc_middle" }
```

---

This approach was [originally proposed for IntelliJ Rust](intellij-rust/intellij-rust#1618 (comment)), and looks like it works for rust-analyzer too.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants