Skip to content

Commit

Permalink
Add DstLayout::extend
Browse files Browse the repository at this point in the history
This method is comparable to `Layout::extend`, but also handles
dynamically sized types.

Makes progress towards #29.
  • Loading branch information
jswrenn committed Nov 23, 2023
1 parent f2c2a55 commit 7b3af4a
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 7 deletions.
479 changes: 472 additions & 7 deletions src/lib.rs

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,22 @@ pub(crate) const fn _round_down_to_next_multiple_of_alignment(
n & mask
}

pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
if a.get() < b.get() {
b
} else {
a
}
}

pub(crate) const fn min(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
if a.get() > b.get() {
b
} else {
a
}
}

/// Since we support multiple versions of Rust, there are often features which
/// have been stabilized in the most recent stable release which do not yet
/// exist (stably) on our MSRV. This module provides polyfills for those
Expand Down
1 change: 1 addition & 0 deletions tests/ui-msrv/max-align.rs
5 changes: 5 additions & 0 deletions tests/ui-msrv/max-align.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
--> tests/ui-msrv/max-align.rs:96:11
|
96 | #[repr(C, align(1073741824))]
| ^^^^^^^^^^^^^^^^^
99 changes: 99 additions & 0 deletions tests/ui-nightly/max-align.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2023 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

#[repr(C, align(1))]
struct Align1;

#[repr(C, align(2))]
struct Align2;

#[repr(C, align(4))]
struct Align4;

#[repr(C, align(8))]
struct Align8;

#[repr(C, align(16))]
struct Align16;

#[repr(C, align(32))]
struct Align32;

#[repr(C, align(64))]
struct Align64;

#[repr(C, align(128))]
struct Align128;

#[repr(C, align(256))]
struct Align256;

#[repr(C, align(512))]
struct Align512;

#[repr(C, align(1024))]
struct Align1024;

#[repr(C, align(2048))]
struct Align2048;

#[repr(C, align(4096))]
struct Align4096;

#[repr(C, align(8192))]
struct Align8192;

#[repr(C, align(16384))]
struct Align16384;

#[repr(C, align(32768))]
struct Align32768;

#[repr(C, align(65536))]
struct Align65536;

#[repr(C, align(131072))]
struct Align131072;

#[repr(C, align(262144))]
struct Align262144;

#[repr(C, align(524288))]
struct Align524288;

#[repr(C, align(1048576))]
struct Align1048576;

#[repr(C, align(2097152))]
struct Align2097152;

#[repr(C, align(4194304))]
struct Align4194304;

#[repr(C, align(8388608))]
struct Align8388608;

#[repr(C, align(16777216))]
struct Align16777216;

#[repr(C, align(33554432))]
struct Align33554432;

#[repr(C, align(67108864))]
struct Align67108864;

#[repr(C, align(134217728))]
struct Align13421772;

#[repr(C, align(268435456))]
struct Align26843545;

#[repr(C, align(1073741824))]
struct Align1073741824;

fn main() {}
5 changes: 5 additions & 0 deletions tests/ui-nightly/max-align.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
--> tests/ui-nightly/max-align.rs:96:11
|
96 | #[repr(C, align(1073741824))]
| ^^^^^^^^^^^^^^^^^
1 change: 1 addition & 0 deletions tests/ui-stable/max-align.rs
5 changes: 5 additions & 0 deletions tests/ui-stable/max-align.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
--> tests/ui-stable/max-align.rs:96:11
|
96 | #[repr(C, align(1073741824))]
| ^^^^^^^^^^^^^^^^^

0 comments on commit 7b3af4a

Please sign in to comment.