Closed
Description
This program:
use std::util::NonCopyable;
struct Foo {
nocopies: NonCopyable
}
fn make_foo() -> Foo {
Foo { nocopies: NonCopyable::new() }
}
fn main() {
let _f:Foo = make_foo();
}
will cause the compiler to crash and print this when compiled with -O
:
Assertion failed: (begin() + idx < end()), function operator[], file /Users/micah/progs/rust/src/llvm/include/llvm/ADT/SmallVector.h, line 140.
Stack dump:
0. Running pass 'Function Pass Manager' on module 'dag_dawg.rc'.
1. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_ZN4main19heaa017369cfad4b1ar4v0.0E'
(dag_dawg.rs
was the file name I tried to compile.) Without -O
it compiles fine. If you replace NonCopyable::new()
with just NonCopyable
it compiles fine, suggesting that NonCopyable::new()
itself is no longer even necessary.
I created my own version of NonCopyable
in another crate and linked to it. The crash reproduced only if, like std::NonCopyable
, my struct had the attribute #[unsafe_no_drop_flag]
.
Add a non-zero-length field to the struct and the crash goes away.