fixes for Box<[T]>
The pointer in the slice must not be null, because enum representations make that assumption. The `exchange_malloc` function returns a non-null sentinel for the zero size case, and it must not be passed to the `exchange_free` lang item. Since the length is always equal to the true capacity, a branch on the length is enough for most types. Slices of zero size types are statically special cased to never attempt deallocation. This is the same implementation as `Vec<T>`. Closes #14395
This commit is contained in:
parent
b625d43f8f
commit
9639cafd36
4 changed files with 24 additions and 37 deletions
|
|
@ -11,6 +11,12 @@
|
|||
pub fn main() {
|
||||
assert!(Some(box() ()).is_some());
|
||||
|
||||
let xs: Box<[()]> = box [];
|
||||
assert!(Some(xs).is_some());
|
||||
|
||||
struct Foo;
|
||||
assert!(Some(box Foo).is_some());
|
||||
|
||||
let ys: Box<[Foo]> = box [];
|
||||
assert!(Some(ys).is_some());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue