Skip to content

Commit

Permalink
chore: Remove static_assertions dependency
Browse files Browse the repository at this point in the history
`static_assertions` seems unmaintained, and anyway `assert!()` is
usable in `const` contexts since Rust 1.57.0:
https://blog.rust-lang.org/2021/12/02/Rust-1.57.0.html#panic-in-const-contexts
So simply use the suggested method instead.

Also the `rustversion` dependency is no longer needed because
rust-lang/rust#94075 already landed in stable.
  • Loading branch information
relrelb committed Mar 25, 2023
1 parent c68a4b0 commit 384af89
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 32 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ lzma-rs = {version = "0.3.0", optional = true }
dasp = { git = "https://github.com/RustAudio/dasp", rev = "f05a703", features = ["interpolate", "interpolate-linear", "signal"], optional = true }
symphonia = { version = "0.5.2", default-features = false, features = ["mp3"], optional = true }
enumset = "1.0.12"
static_assertions = "1.1.0"
rustversion = "1.0.12"
bytemuck = "1.13.1"
clap = { version = "4.1.11", features = ["derive"], optional=true }
realfft = "3.2.0"
Expand Down
13 changes: 4 additions & 9 deletions core/src/avm2/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::avm2::Activation;
use crate::avm2::AvmString;
use crate::avm2::Multiname;
use crate::avm2::Value;
use std::mem::size_of;

use super::ClassObject;

Expand Down Expand Up @@ -34,17 +35,11 @@ impl<'gc> Error<'gc> {
}

// This type is used very frequently, so make sure it doesn't unexpectedly grow.
// For now, we only test on Nightly, since a new niche optimization was recently
// added (https://github.com/rust-lang/rust/pull/94075) that shrinks the size
// relative to stable.
#[cfg(target_family = "wasm")]
const _: () = assert!(size_of::<Result<Value<'_>, Error<'_>>>() == 24);

#[rustversion::nightly]
#[cfg(target_arch = "wasm32")]
static_assertions::assert_eq_size!(Result<Value<'_>, Error<'_>>, [u8; 24]);

#[rustversion::nightly]
#[cfg(target_pointer_width = "64")]
static_assertions::assert_eq_size!(Result<Value<'_>, Error<'_>>, [u8; 32]);
const _: () = assert!(size_of::<Result<Value<'_>, Error<'_>>>() == 32);

#[inline(never)]
#[cold]
Expand Down
12 changes: 4 additions & 8 deletions core/src/avm2/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::ecma_conversions::{f64_to_wrapping_i32, f64_to_wrapping_u32};
use crate::string::{AvmString, WStr};
use gc_arena::{Collect, GcCell, MutationContext};
use std::cell::Ref;
use std::mem::size_of;
use swf::avm2::types::{DefaultValue as AbcDefaultValue, Index};

use super::e4x::E4XNode;
Expand Down Expand Up @@ -49,16 +50,11 @@ pub enum Value<'gc> {
}

// This type is used very frequently, so make sure it doesn't unexpectedly grow.
// For now, we only test on Nightly, since a new niche optimization was recently
// added (https://github.com/rust-lang/rust/pull/94075) that shrinks the size
// relative to stable.
#[cfg(target_family = "wasm")]
const _: () = assert!(size_of::<Value<'_>>() == 16);

#[cfg(target_arch = "wasm32")]
static_assertions::assert_eq_size!(Value<'_>, [u8; 16]);

#[rustversion::nightly]
#[cfg(target_pointer_width = "64")]
static_assertions::assert_eq_size!(Value<'_>, [u8; 24]);
const _: () = assert!(size_of::<Value<'_>>() == 24);

impl<'gc> From<AvmString<'gc>> for Value<'gc> {
fn from(string: AvmString<'gc>) -> Self {
Expand Down
3 changes: 0 additions & 3 deletions wstr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ homepage.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
static_assertions = "1.1.0"
9 changes: 4 additions & 5 deletions wstr/src/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use alloc::borrow::ToOwned;
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt;
use core::mem::{self, ManuallyDrop};
use core::mem::{self, size_of, ManuallyDrop};
use core::ops::{Deref, DerefMut};
use core::ptr::NonNull;
use static_assertions::assert_eq_size;

use super::utils::{encode_raw_utf16, split_ascii_prefix, split_ascii_prefix_bytes, DecodeAvmUtf8};
use super::{ptr, Units, WStr, MAX_STRING_LEN};
Expand All @@ -17,11 +16,11 @@ pub struct WString {
capacity: u32,
}

#[cfg(target_pointer_width = "32")]
assert_eq_size!(WString, [u8; 12]);
#[cfg(target_family = "wasm")]
const _: () = assert!(size_of::<WString>() == 12);

#[cfg(target_pointer_width = "64")]
assert_eq_size!(WString, [u8; 16]);
const _: () = assert!(size_of::<WString>() == 16);

impl WString {
/// Creates a new empty `WString`.
Expand Down

0 comments on commit 384af89

Please sign in to comment.