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

Returning a struct that holds an owned trait object results in a segfault #6717

Closed
zargony opened this issue May 24, 2013 · 3 comments
Closed

Comments

@zargony
Copy link
Contributor

zargony commented May 24, 2013

Using rustc 0.6, the compiled executable of the following code results in a segfault. I'm not exactly sure why, but I suppose this shouldn't happen ;).

Btw, using @Animal instead of ~Animal works fine. Using @Cage or ~Cage doesn't matter (both crash). Building ~Cage directly in main() also works fine.

pub trait Animal { }

struct Cage {
  animal: ~Animal,
}

fn capture (animal: ~Animal) -> ~Cage {
  let cage = ~Cage { animal: animal };
  debug!("still alive");
  cage
}

struct Duck { foo: int }

impl Animal for Duck { }

fn main () {
  let duck = ~Duck { foo: 123 };
  let _ = capture(duck as ~Animal);
  debug!("never reached");
}


zargony@lina:~$ uname -a
Darwin lina.fritz.box 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan  6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
zargony@lina:~$ rustc --version
rustc 0.6
host: x86_64-apple-darwin
@zargony
Copy link
Contributor Author

zargony commented May 24, 2013

Same with rustc from master branch (rev 2d28d64)

@zargony
Copy link
Contributor Author

zargony commented Jun 13, 2013

Latest rustc from incoming branch (rev 9355330) fails to compile this example:

Assertion failed: (Ty && "Invalid GetElementPtrInst indices for type!"), function checkGEPType, file /private/tmp/rust-Fx9w/src/llvm/include/llvm/IR/Instructions.h, line 704.
Abort trap: 6

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.
@thestinger
Copy link
Contributor

Fixed by #7214.

flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 25, 2021
Add the from_str_radix_10 lint

changelog: added the new `from_str_radix_10` which sometimes replaces calls to `primitive::from_str_radix` to `str::parse`

This is ready to be merged, although maybe the category should be `pedantic` instead of `style`? I'm not sure where it fits better.

Closes rust-lang#6713.
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

No branches or pull requests

2 participants