diff options
| author | James Miller <james@aatch.net> | 2015-12-08 15:40:25 +1300 |
|---|---|---|
| committer | James Miller <james@aatch.net> | 2015-12-08 15:55:00 +1300 |
| commit | d6eb063fe8c60ff7cbd83c7a27ba4bc6a24bd174 (patch) | |
| tree | 13fd695a427e86970ea7f16ee9ed2165fc58e321 /src/test | |
| parent | a2557d472e570559caf18d9b042cd941f5002398 (diff) | |
| download | rust-d6eb063fe8c60ff7cbd83c7a27ba4bc6a24bd174.tar.gz rust-d6eb063fe8c60ff7cbd83c7a27ba4bc6a24bd174.zip | |
Fix unsized structs with destructors
The presence of the drop flag caused the offset calculation to be incorrect, leading to the pointer being incorrect. This has been fixed by calculating the offset based on the field index (and not assuming that the field is always the last one). However, I've also stopped the drop flag from being added to the end of unsized structs to begin with. Since it's not actually accessed for unsized structs, and isn't actually where we would say it is, this made more sense.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/dst-field-align.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/test/run-pass/dst-field-align.rs b/src/test/run-pass/dst-field-align.rs index 552734820f2..cf2acfe986c 100644 --- a/src/test/run-pass/dst-field-align.rs +++ b/src/test/run-pass/dst-field-align.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo<T: ?Sized> { - a: u8, + a: u16, b: T } @@ -31,6 +31,11 @@ struct Packed<T: ?Sized> { b: T } +struct HasDrop<T: ?Sized> { + ptr: Box<usize>, + data: T +} + fn main() { // Test that zero-offset works properly let b : Baz<usize> = Baz { a: 7 }; @@ -68,4 +73,15 @@ fn main() { let f : &Foo<Bar> = &f; let &Foo { a: _, b: ref bar } = f; assert_eq!(bar.get(), 11); + + // Make sure that drop flags don't screw things up + + let d : HasDrop<Baz<[i32; 4]>> = HasDrop { + ptr: Box::new(0), + data: Baz { a: [1,2,3,4] } + }; + assert_eq!([1,2,3,4], d.data.a); + + let d : &HasDrop<Baz<[i32]>> = &d; + assert_eq!(&[1,2,3,4], &d.data.a); } |
