diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2019-10-15 16:07:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-15 16:07:53 -0700 |
| commit | bbcf66a4a177c1756d5b6845933e6cb06aa21b2c (patch) | |
| tree | e8afbeeb22cc0a0ddc3e088dadfd0aa5150d35e9 /src/test | |
| parent | 820fb7ccbf2fa6116ce09a178b2deb9e9b736704 (diff) | |
| parent | c08a8713381ed67caea826a793145240cd873081 (diff) | |
| download | rust-bbcf66a4a177c1756d5b6845933e6cb06aa21b2c.tar.gz rust-bbcf66a4a177c1756d5b6845933e6cb06aa21b2c.zip | |
Rollup merge of #65389 - ecstatic-morse:zero-sized-array-no-drop, r=eddyb
Return `false` from `needs_drop` for all zero-sized arrays. Resolves #65348. This changes the result of the `needs_drop` query from `true` to `false` for types such as `[Box<i32>; 0]`. I believe this change to be sound because a zero-sized array can never actually hold a value. This is an elegant way of resolving #65348 and #64945, but obviously it has much broader implications.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/consts/issue-65348.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/ui/consts/issue-65348.rs b/src/test/ui/consts/issue-65348.rs new file mode 100644 index 00000000000..5eafa831d63 --- /dev/null +++ b/src/test/ui/consts/issue-65348.rs @@ -0,0 +1,23 @@ +// check-pass + +struct Generic<T>(T); + +impl<T> Generic<T> { + const ARRAY: [T; 0] = []; + const NEWTYPE_ARRAY: Generic<[T; 0]> = Generic([]); + const ARRAY_FIELD: Generic<(i32, [T; 0])> = Generic((0, [])); +} + +pub const fn array<T>() -> &'static T { + &Generic::<T>::ARRAY[0] +} + +pub const fn newtype_array<T>() -> &'static T { + &Generic::<T>::NEWTYPE_ARRAY.0[0] +} + +pub const fn array_field<T>() -> &'static T { + &(Generic::<T>::ARRAY_FIELD.0).1[0] +} + +fn main() {} |
