Make crate contents match upstream.
Our repo looks like it was mirrored from the github repo after v1.1.0 of
the crate was released. There have been no new versions since then.
Bug: http://b/339424309
Test: treehugger
Change-Id: I68d79fe50941541442891732b1c577c78e181dad
diff --git a/Cargo.toml b/Cargo.toml
index 39a4793..8651ce1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,28 +1,39 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
[package]
name = "static_assertions"
version = "1.1.0"
authors = ["Nikolai Vazquez"]
-license = "MIT OR Apache-2.0"
-readme = "README.md"
-homepage = "https://github.com/nvzqz/static-assertions-rs"
-repository = "https://github.com/nvzqz/static-assertions-rs"
-documentation = "https://docs.rs/static_assertions/"
-categories = ["no-std", "rust-patterns", "development-tools::testing"]
-keywords = ["assert", "static", "testing"]
-description = "Compile-time assertions to ensure that invariants are met."
include = ["Cargo.toml", "src/**/*.rs", "README.md", "CHANGELOG.md", "LICENSE*"]
-
-[dependencies.proc_static_assertions]
-version = "0.0.0"
-path = "proc"
-optional = true
-
-[workspace]
-members = ["proc"]
+description = "Compile-time assertions to ensure that invariants are met."
+homepage = "https://github.com/nvzqz/static-assertions-rs"
+documentation = "https://docs.rs/static_assertions/"
+readme = "README.md"
+keywords = ["assert", "static", "testing"]
+categories = ["no-std", "rust-patterns", "development-tools::testing"]
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/nvzqz/static-assertions-rs"
[features]
nightly = []
-proc = ["proc_static_assertions"]
+[badges.is-it-maintained-issue-resolution]
+repository = "nvzqz/static-assertions-rs"
-[badges]
-maintenance = { status = "actively-maintained" }
+[badges.is-it-maintained-open-issues]
+repository = "nvzqz/static-assertions-rs"
+
+[badges.maintenance]
+status = "passively-maintained"
+
+[badges.travis-ci]
+repository = "nvzqz/static-assertions-rs"
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..ccc9445
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017 Nikolai Vazquez
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index 75ddd70..bca222e 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,8 @@
<img src="https://img.shields.io/crates/v/static_assertions.svg" alt="Crates.io">
<img src="https://img.shields.io/crates/d/static_assertions.svg" alt="Downloads">
</a>
- <a href="https://github.com/nvzqz/static-assertions-rs/actions?query=workflow%3ACI">
- <img src="https://github.com/nvzqz/static-assertions-rs/workflows/CI/badge.svg" alt="Build Status">
+ <a href="https://travis-ci.org/nvzqz/static-assertions-rs">
+ <img src="https://travis-ci.org/nvzqz/static-assertions-rs.svg?branch=master" alt="Build Status">
</a>
<img src="https://img.shields.io/badge/rustc-^1.37.0-blue.svg" alt="rustc ^1.37.0">
<br>
diff --git a/patches/dylib-std.patch b/patches/dylib-std.patch
index 7864526..0ca522e 100644
--- a/patches/dylib-std.patch
+++ b/patches/dylib-std.patch
@@ -1,14 +1,14 @@
diff --git a/src/lib.rs b/src/lib.rs
-index aa7e227..df47529 100644
+index a43cc1f..d9f1523 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -101,6 +101,9 @@
- )]
- #![no_std]
+@@ -83,6 +83,9 @@
+
+ #![deny(unused_macros)]
+#[cfg(android_dylib)]
+extern crate std;
+
- #[cfg(feature = "proc_static_assertions")]
- extern crate proc_static_assertions;
- #[cfg(feature = "proc_static_assertions")]
+ #[doc(hidden)]
+ pub extern crate core as _core;
+
diff --git a/proc/Android.bp b/proc/Android.bp
deleted file mode 100644
index df009c9..0000000
--- a/proc/Android.bp
+++ /dev/null
@@ -1,20 +0,0 @@
-// This file is generated by cargo_embargo.
-// Do not modify this file because the changes will be overridden on upgrade.
-
-package {
- default_applicable_licenses: ["external_rust_crates_proc_static_assertions_license"],
- default_team: "trendy_team_android_rust",
-}
-
-license {
- name: "external_rust_crates_proc_static_assertions_license",
- visibility: [":__subpackages__"],
- license_kinds: ["SPDX-license-identifier-Apache-2.0"],
- license_text: ["LICENSE"],
-}
-
-dirgroup {
- name: "trusty_dirgroup_external_rust_crates_proc_static_assertions",
- visibility: ["//trusty/vendor/google/aosp/scripts"],
- dirs: ["."],
-}
diff --git a/proc/Cargo.toml b/proc/Cargo.toml
deleted file mode 100644
index d1f7d69..0000000
--- a/proc/Cargo.toml
+++ /dev/null
@@ -1,25 +0,0 @@
-[package]
-name = "proc_static_assertions"
-version = "0.0.0"
-authors = ["Nikolai Vazquez"]
-license = "MIT OR Apache-2.0"
-readme = "../README.md"
-homepage = "https://github.com/nvzqz/static-assertions-rs"
-repository = "https://github.com/nvzqz/static-assertions-rs"
-documentation = "https://docs.rs/proc_static_assertions/"
-categories = ["no-std", "rust-patterns", "development-tools::testing"]
-keywords = ["assert", "static", "testing"]
-description = "Compile-time assertions via procedural macros."
-include = ["Cargo.toml", "src/**/*.rs", "README.md", "CHANGELOG.md", "LICENSE*"]
-
-[lib]
-proc-macro = true
-
-[badges]
-travis-ci = { repository = "nvzqz/static-assertions-rs" }
-is-it-maintained-open-issues = { repository = "nvzqz/static-assertions-rs" }
-is-it-maintained-issue-resolution = { repository = "nvzqz/static-assertions-rs" }
-maintenance = { status = "passively-maintained" }
-
-[features]
-nightly = []
diff --git a/proc/LICENSE b/proc/LICENSE
deleted file mode 120000
index ea5b606..0000000
--- a/proc/LICENSE
+++ /dev/null
@@ -1 +0,0 @@
-../LICENSE
\ No newline at end of file
diff --git a/proc/rules.mk b/proc/rules.mk
deleted file mode 100644
index efdf5d9..0000000
--- a/proc/rules.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-# This file is generated by cargo_embargo.
-# Do not modify this file after the LOCAL_DIR line
-# because the changes will be overridden on upgrade.
-# Content before the first line starting with LOCAL_DIR is preserved.
-// DO NOT SUBMIT: Add license before submitting.
-LOCAL_DIR := $(GET_LOCAL_DIR)
-MODULE := $(LOCAL_DIR)
-MODULE_CRATE_NAME := proc_static_assertions
-MODULE_RUST_CRATE_TYPES := proc-macro
-MODULE_SRCS := $(LOCAL_DIR)/src/lib.rs
-MODULE_RUST_EDITION := 2015
-MODULE_LIBRARY_DEPS := \
-
-
-include make/library.mk
diff --git a/proc/src/lib.rs b/proc/src/lib.rs
deleted file mode 100644
index 4812c3c..0000000
--- a/proc/src/lib.rs
+++ /dev/null
@@ -1,92 +0,0 @@
-//! [](https://github.com/nvzqz/static-assertions-rs)
-//!
-//! <div align="center">
-//! <a href="https://crates.io/crates/proc_static_assertions">
-//! <img src="https://img.shields.io/crates/d/proc_static_assertions.svg" alt="Downloads">
-//! </a>
-//! <a href="https://travis-ci.org/nvzqz/static-assertions-rs">
-//! <img src="https://travis-ci.org/nvzqz/static-assertions-rs.svg?branch=master" alt="Build Status">
-//! </a>
-//! <br><br>
-//! </div>
-//!
-//! Procedural macro [compile-time] assertions as an extension of
-//! [`static_assertions`].
-//!
-//! # Usage
-//!
-//! There's two main ways of using this crate: as a direct dependency or
-//! indirect dependency (via [`static_assertions`]).
-//!
-//! ## Direct Dependency
-//!
-//! This crate is available [on crates.io][crate] and can be used by adding the
-//! following to your project's [`Cargo.toml`]:
-//!
-//! ```toml
-//! [dependencies]
-//! proc_static_assertions = "0.0.0"
-//! ```
-//!
-//! and this to your crate root (`main.rs` or `lib.rs`):
-//!
-//! ```
-//! #[macro_use]
-//! extern crate proc_static_assertions;
-//! # fn main() {}
-//! ```
-//!
-//! ## Indirect Dependency
-//!
-//! Add the following to your project's [`Cargo.toml`]:
-//!
-//! ```toml
-//! [dependencies]
-//! static_assertions = { version = "1.1.0", features = ["proc"] }
-//! ```
-//!
-//! and this to your crate root (`main.rs` or `lib.rs`):
-//!
-//! ```ignore
-//! #[macro_use]
-//! extern crate static_assertions;
-//! ```
-//!
-//! This will also import all macros in `proc_static_assertions`.
-//!
-//! # Donate
-//!
-//! This project is made freely available (as in free beer), but unfortunately
-//! not all beer is free! So, if you would like to buy me a beer (or coffee or
-//! *more*), then consider supporting my work that's benefited your project
-//! and thousands of others.
-//!
-//! <a href="https://www.patreon.com/nvzqz">
-//! <img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" height="35">
-//! </a>
-//! <a href="https://www.paypal.me/nvzqz">
-//! <img src="https://buymecoffee.intm.org/img/button-paypal-white.png" alt="Buy me a coffee" height="35">
-//! </a>
-//!
-//! [`static_assertions`]: https://github.com/nvzqz/static-assertions-rs
-//! [crate]: https://crates.io/crates/static_assertions
-//! [`Cargo.toml`]: https://doc.rust-lang.org/cargo/reference/manifest.html
-//! [compile-time]: https://en.wikipedia.org/wiki/Compile_time
-
-#![doc(html_root_url = "https://docs.rs/proc_static_assertions/0.0.0")]
-#![doc(
- html_logo_url = "https://raw.githubusercontent.com/nvzqz/static-assertions-rs/assets/Icon.png"
-)]
-#![deny(missing_docs)]
-
-extern crate proc_macro;
-use proc_macro::TokenStream;
-
-/// Statically assert aspects of types, traits, and more.
-///
-/// This currently does nothing. Create an issue if you have ideas for what this
-/// could do!
-#[proc_macro_attribute]
-pub fn assert(_attr: TokenStream, _item: TokenStream) -> TokenStream {
- TokenStream::new()
-}
diff --git a/proc/tests/size.rs b/proc/tests/size.rs
deleted file mode 100644
index 1550547..0000000
--- a/proc/tests/size.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-#[macro_use]
-extern crate proc_static_assertions;
-
-#[assert(size == 4, align == 4)]
-struct Foo {
- value: i32,
-}
diff --git a/rustfmt.toml b/rustfmt.toml
deleted file mode 100644
index c9cc71a..0000000
--- a/rustfmt.toml
+++ /dev/null
@@ -1,15 +0,0 @@
-max_width = 80
-hard_tabs = false
-tab_spaces = 4
-newline_style = "Unix"
-use_small_heuristics = "Default"
-reorder_imports = true
-reorder_modules = true
-remove_nested_parens = true
-fn_args_layout = "Tall"
-edition = "2018"
-merge_derives = true
-use_try_shorthand = false
-use_field_init_shorthand = true
-force_explicit_abi = true
-print_misformatted_file_names = true
diff --git a/src/assert_align.rs b/src/assert_align.rs
deleted file mode 100644
index f1de642..0000000
--- a/src/assert_align.rs
+++ /dev/null
@@ -1,200 +0,0 @@
-/// Asserts that the types' alignments are equal.
-///
-/// This is useful when ensuring that pointer arithmetic is done correctly, or
-/// when [FFI] requires a type to have the same alignment as some foreign type.
-///
-/// # Examples
-///
-/// A `usize` has the same alignment as any pointer type:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_eq!(usize, *const u8, *mut u8);
-/// ```
-///
-/// The following passes because `[i32; 4]` has the same alignment as `i32`:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_eq!([i32; 4], i32);
-/// ```
-///
-/// The following example fails to compile because `i32x4` explicitly has 4
-/// times the alignment as `[i32; 4]`:
-///
-/// ```compile_fail
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// # #[allow(non_camel_case_types)]
-/// #[repr(align(16))]
-/// struct i32x4([i32; 4]);
-///
-/// assert_align_eq!(i32x4, [i32; 4]);
-/// ```
-///
-/// [FFI]: https://en.wikipedia.org/wiki/Foreign_function_interface
-#[macro_export(local_inner_macros)]
-macro_rules! assert_align_eq {
- ($x:ty, $($y:ty),+ $(,)?) => {
- const _: fn() = || {
- use $crate::_core::mem::align_of;
- const_assert_eq_usize!(align_of::<$x>() $(, align_of::<$y>())+);
- };
- };
-}
-
-/// Asserts that the types' alignments are equal.
-///
-/// This macro has been deprecated in favor of
-/// [`assert_align_eq!`](macro.assert_align_eq.html).
-#[deprecated(
- since = "1.2.0",
- note = "Please use the 'assert_align_eq' macro instead"
-)]
-#[macro_export(local_inner_macros)]
-macro_rules! assert_eq_align {
- ($($t:tt)*) => {
- assert_align_eq!($($t)*);
- };
-}
-
-/// Asserts that the types' alignments are **not** equal.
-///
-/// # Examples
-///
-/// A `u8` does not have the same alignment as a pointer:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_ne!(u8, *const u8);
-/// ```
-///
-/// The following example fails to compile because a `usize` has the same
-/// alignment as a pointer:
-///
-/// ```compile_fail
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_ne!(*const u8, usize);
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! assert_align_ne {
- ($x:ty, $($y:ty),+ $(,)?) => {
- const _: fn() = || {
- use $crate::_core::mem::align_of;
- const_assert_ne!(align_of::<$x>() $(, align_of::<$y>())+);
- };
- };
-}
-
-/// Asserts that the types' alignments are less than each other.
-///
-/// # Examples
-///
-/// A `u8` has smaller alignment than `u16`, which has smaller alignment than
-/// a pointer:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_lt!(u8, u16, *const u8);
-/// ```
-///
-/// The following example fails to compile because a `usize` has the same
-/// alignment as a pointer:
-///
-/// ```compile_fail
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_lt!(*const u8, usize);
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! assert_align_lt {
- ($x:ty, $($y:ty),+ $(,)?) => {
- const _: fn() = || {
- use $crate::_core::mem::align_of;
- const_assert_lt!(align_of::<$x>() $(, align_of::<$y>())+);
- };
- };
-}
-
-/// Asserts that the types' alignments are less than or equal to each other.
-///
-/// # Examples
-///
-/// A `u8` and `i8` have smaller alignment than any pointer type:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_le!(u8, i8, *const u8);
-/// ```
-///
-/// The following example fails to compile because a `usize` has greater
-/// alignment than `u8`:
-///
-/// ```compile_fail
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_le!(usize, u8);
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! assert_align_le {
- ($x:ty, $($y:ty),+ $(,)?) => {
- const _: fn() = || {
- use $crate::_core::mem::align_of;
- const_assert_le!(align_of::<$x>() $(, align_of::<$y>())+);
- };
- };
-}
-
-/// Asserts that the types' alignments are greater than each other.
-///
-/// # Examples
-///
-/// A pointer has greater alignment than `u16`, which has greater alignment than
-/// `u8`:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_gt!(*const u8, u16, u8);
-/// ```
-///
-/// The following example fails to compile because a `usize` has the same
-/// alignment as a pointer:
-///
-/// ```compile_fail
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_gt!(*const u8, usize);
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! assert_align_gt {
- ($x:ty, $($y:ty),+ $(,)?) => {
- const _: fn() = || {
- use $crate::_core::mem::align_of;
- const_assert_gt!(align_of::<$x>() $(, align_of::<$y>())+);
- };
- };
-}
-
-/// Asserts that the types' alignments are greater than or equal to each other.
-///
-/// # Examples
-///
-/// A pointer has greater alignment than `u8` and `i8`:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_ge!(*const u8, u8, i8);
-/// ```
-///
-/// The following example fails to compile because a `u8` has smaller alignment
-/// than `usize`:
-///
-/// ```compile_fail
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_align_ge!(u8, usize);
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! assert_align_ge {
- ($x:ty, $($y:ty),+ $(,)?) => {
- const _: fn() = || {
- use $crate::_core::mem::align_of;
- const_assert_ge!(align_of::<$x>() $(, align_of::<$y>())+);
- };
- };
-}
diff --git a/src/assert_eq_align.rs b/src/assert_eq_align.rs
new file mode 100644
index 0000000..69412da
--- /dev/null
+++ b/src/assert_eq_align.rs
@@ -0,0 +1,45 @@
+/// Asserts that types are equal in alignment.
+///
+/// This is useful when ensuring that pointer arithmetic is done correctly, or
+/// when [FFI] requires a type to have the same alignment as some foreign type.
+///
+/// # Examples
+///
+/// A `usize` has the same alignment as any pointer type:
+///
+/// ```
+/// # #[macro_use] extern crate static_assertions; fn main() {}
+/// assert_eq_align!(usize, *const u8, *mut u8);
+/// ```
+///
+/// The following passes because `[i32; 4]` has the same alignment as `i32`:
+///
+/// ```
+/// # #[macro_use] extern crate static_assertions; fn main() {}
+/// assert_eq_align!([i32; 4], i32);
+/// ```
+///
+/// The following example fails to compile because `i32x4` explicitly has 4
+/// times the alignment as `[i32; 4]`:
+///
+/// ```compile_fail
+/// # #[macro_use] extern crate static_assertions; fn main() {}
+/// # #[allow(non_camel_case_types)]
+/// #[repr(align(16))]
+/// struct i32x4([i32; 4]);
+///
+/// assert_eq_align!(i32x4, [i32; 4]);
+/// ```
+///
+/// [FFI]: https://en.wikipedia.org/wiki/Foreign_function_interface
+#[macro_export]
+macro_rules! assert_eq_align {
+ ($x:ty, $($xs:ty),+ $(,)?) => {
+ const _: fn() = || {
+ // Assigned instance must match the annotated type or else it will
+ // fail to compile
+ use $crate::_core::mem::align_of;
+ $(let _: [(); align_of::<$x>()] = [(); align_of::<$xs>()];)+
+ };
+ };
+}
diff --git a/src/assert_size.rs b/src/assert_eq_size.rs
similarity index 64%
rename from src/assert_size.rs
rename to src/assert_eq_size.rs
index e1a7067..9c3c490 100644
--- a/src/assert_size.rs
+++ b/src/assert_eq_size.rs
@@ -6,8 +6,8 @@
///
/// # Alternatives
///
-/// There also exists [`assert_size_eq_val`](macro.assert_size_eq_val.html) and
-/// [`assert_size_eq_ptr`](macro.assert_size_eq_ptr.html). Instead of specifying
+/// There also exists [`assert_eq_size_val`](macro.assert_eq_size_val.html) and
+/// [`assert_eq_size_ptr`](macro.assert_eq_size_ptr.html). Instead of specifying
/// types to compare, values' sizes can be directly compared against each other.
///
/// # Examples
@@ -16,7 +16,7 @@
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_size_eq!([u8; 4], (u16, u16), u32);
+/// assert_eq_size!([u8; 4], (u16, u16), u32);
/// ```
///
/// The following example fails to compile because `u32` has 4 times the size of
@@ -24,14 +24,14 @@
///
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_size_eq!(u32, u8);
+/// assert_eq_size!(u32, u8);
/// ```
///
/// [`usize`]: https://doc.rust-lang.org/std/primitive.usize.html
/// [`u64`]: https://doc.rust-lang.org/std/primitive.u64.html
/// [`u32`]: https://doc.rust-lang.org/std/primitive.u32.html
#[macro_export]
-macro_rules! assert_size_eq {
+macro_rules! assert_eq_size {
($x:ty, $($xs:ty),+ $(,)?) => {
const _: fn() = || {
$(let _ = $crate::_core::mem::transmute::<$x, $xs>;)+
@@ -39,21 +39,6 @@
};
}
-/// Asserts that types are equal in alignment.
-///
-/// This macro has been deprecated in favor of
-/// [`assert_size_eq!`](macro.assert_size_eq.html).
-#[deprecated(
- since = "1.2.0",
- note = "Please use the 'assert_size_eq' macro instead"
-)]
-#[macro_export(local_inner_macros)]
-macro_rules! assert_eq_size {
- ($($t:tt)*) => {
- assert_size_eq!($($t)*);
- };
-}
-
/// Asserts that values pointed to are equal in size.
///
/// # Examples
@@ -64,7 +49,7 @@
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
/// fn operation(x: &(u32, u32), y: &[u16; 4]) {
-/// assert_size_eq_ptr!(x, y);
+/// assert_eq_size_ptr!(x, y);
/// // ...
/// }
/// ```
@@ -85,10 +70,10 @@
/// # 0; 16
/// ];
///
-/// assert_size_eq_ptr!(BYTES, TABLE);
+/// assert_eq_size_ptr!(BYTES, TABLE);
/// ```
#[macro_export]
-macro_rules! assert_size_eq_ptr {
+macro_rules! assert_eq_size_ptr {
($x:expr, $($xs:expr),+ $(,)?) => {
#[allow(unknown_lints, unsafe_code, forget_copy, useless_transmute)]
let _ = || unsafe {
@@ -100,21 +85,6 @@
}
}
-/// Asserts that values pointed to are equal in size.
-///
-/// This macro has been deprecated in favor of
-/// [`assert_size_eq_ptr!`](macro.assert_size_eq_ptr.html).
-#[deprecated(
- since = "1.2.0",
- note = "Please use the 'assert_size_eq_ptr' macro instead"
-)]
-#[macro_export(local_inner_macros)]
-macro_rules! assert_eq_size_ptr {
- ($($t:tt)*) => {
- assert_size_eq_ptr!($($t)*);
- };
-}
-
/// Asserts that values are equal in size.
///
/// This macro doesn't consume its arguments and thus works for
@@ -130,8 +100,8 @@
/// let x = 10u8;
/// let y = Byte(42); // Works for non-cloneable types
///
-/// assert_size_eq_val!(x, y);
-/// assert_size_eq_val!(x, y, 0u8);
+/// assert_eq_size_val!(x, y);
+/// assert_eq_size_val!(x, y, 0u8);
/// # }
/// ```
///
@@ -140,29 +110,14 @@
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions;
/// # fn main() {
-/// assert_size_eq_val!(0u8, 0u32);
+/// assert_eq_size_val!(0u8, 0u32);
/// # }
/// ```
///
/// [`Clone`]: https://doc.rust-lang.org/std/clone/trait.Clone.html
#[macro_export(local_inner_macros)]
-macro_rules! assert_size_eq_val {
- ($x:expr, $($xs:expr),+ $(,)?) => {
- assert_size_eq_ptr!(&$x, $(&$xs),+);
- }
-}
-
-/// Asserts that values pointed to are equal in size.
-///
-/// This macro has been deprecated in favor of
-/// [`assert_size_eq_val!`](macro.assert_size_eq_val.html).
-#[deprecated(
- since = "1.2.0",
- note = "Please use the 'assert_size_eq_val' macro instead"
-)]
-#[macro_export(local_inner_macros)]
macro_rules! assert_eq_size_val {
- ($($t:tt)*) => {
- assert_size_eq_val!($($t)*);
- };
+ ($x:expr, $($xs:expr),+ $(,)?) => {
+ assert_eq_size_ptr!(&$x, $(&$xs),+);
+ }
}
diff --git a/src/assert_impl.rs b/src/assert_impl.rs
index 83545ca..480b6b6 100644
--- a/src/assert_impl.rs
+++ b/src/assert_impl.rs
@@ -3,8 +3,8 @@
/// Related:
/// - [`assert_impl_any!`]
/// - [`assert_impl_all!`]
-/// - [`assert_impl_not_all!`]
-/// - [`assert_impl_not_any!`]
+/// - [`assert_not_impl_all!`]
+/// - [`assert_not_impl_any!`]
///
/// # Examples
///
@@ -51,8 +51,8 @@
///
/// [`assert_impl_any!`]: macro.assert_impl_any.html
/// [`assert_impl_all!`]: macro.assert_impl_all.html
-/// [`assert_impl_not_all!`]: macro.assert_not_impl_all.html
-/// [`assert_impl_not_any!`]: macro.assert_not_impl_any.html
+/// [`assert_not_impl_all!`]: macro.assert_not_impl_all.html
+/// [`assert_not_impl_any!`]: macro.assert_not_impl_any.html
#[macro_export]
macro_rules! assert_impl_one {
($x:ty: $($t:path),+ $(,)?) => {
@@ -84,7 +84,7 @@
/// Asserts that the type implements _all_ of the given traits.
///
-/// See [`assert_impl_not_all!`] for achieving the opposite effect.
+/// See [`assert_not_impl_all!`] for achieving the opposite effect.
///
/// # Examples
///
@@ -105,20 +105,24 @@
/// assert_impl_all!(*const u8: Send);
/// ```
///
-/// [`assert_impl_not_all!`]: macro.assert_not_impl_all.html
+/// [`assert_not_impl_all!`]: macro.assert_not_impl_all.html
/// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
/// [`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
/// [blanket]: https://doc.rust-lang.org/book/ch10-02-traits.html#using-trait-bounds-to-conditionally-implement-methods
-#[macro_export(local_inner_macros)]
+#[macro_export]
macro_rules! assert_impl_all {
- ($ty:ty: $($traits:path),+ $(,)?) => {
- assert_impl!($ty: $( ($traits) )&+);
+ ($type:ty: $($trait:path),+ $(,)?) => {
+ const _: fn() = || {
+ // Only callable when `$type` implements all traits in `$($trait)+`.
+ fn assert_impl_all<T: ?Sized $(+ $trait)+>() {}
+ assert_impl_all::<$type>();
+ };
};
}
/// Asserts that the type implements _any_ of the given traits.
///
-/// See [`assert_impl_not_any!`] for achieving the opposite effect.
+/// See [`assert_not_impl_any!`] for achieving the opposite effect.
///
/// # Examples
///
@@ -146,13 +150,64 @@
/// assert_impl_any!(*const u8: Send, Sync);
/// ```
///
-/// [`assert_impl_not_any!`]: macro.assert_not_impl_any.html
+/// [`assert_not_impl_any!`]: macro.assert_not_impl_any.html
/// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
/// [`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
-#[macro_export(local_inner_macros)]
+#[macro_export]
macro_rules! assert_impl_any {
- ($ty:ty: $($traits:path),+ $(,)?) => {
- assert_impl!($ty: $( ($traits) )|+);
+ ($x:ty: $($t:path),+ $(,)?) => {
+ const _: fn() = || {
+ use $crate::_core::marker::PhantomData;
+ use $crate::_core::ops::Deref;
+
+ // Fallback to use as the first iterative assignment to `previous`.
+ let previous = AssertImplAnyFallback;
+ struct AssertImplAnyFallback;
+
+ // Ensures that blanket traits can't impersonate the method. This
+ // prevents a false positive attack where---if a blanket trait is in
+ // scope that has `_static_assertions_impl_any`---the macro will
+ // compile when it shouldn't.
+ //
+ // See https://github.com/nvzqz/static-assertions-rs/issues/19 for
+ // more info.
+ struct ActualAssertImplAnyToken;
+ trait AssertImplAnyToken {}
+ impl AssertImplAnyToken for ActualAssertImplAnyToken {}
+ fn assert_impl_any_token<T: AssertImplAnyToken>(_: T) {}
+
+ $(let previous = {
+ struct Wrapper<T, N>(PhantomData<T>, N);
+
+ // If the method for this wrapper can't be called then the
+ // compiler will insert a deref and try again. This forwards the
+ // compiler's next attempt to the previous wrapper.
+ impl<T, N> Deref for Wrapper<T, N> {
+ type Target = N;
+
+ fn deref(&self) -> &Self::Target {
+ &self.1
+ }
+ }
+
+ // This impl is bounded on the `$t` trait, so the method can
+ // only be called if `$x` implements `$t`. This is why a new
+ // `Wrapper` is defined for each `previous`.
+ impl<T: $t, N> Wrapper<T, N> {
+ fn _static_assertions_impl_any(&self) -> ActualAssertImplAnyToken {
+ ActualAssertImplAnyToken
+ }
+ }
+
+ Wrapper::<$x, _>(PhantomData, previous)
+ };)+
+
+ // Attempt to find the method that can actually be called. The found
+ // method must return a type that implements the sealed `Token`
+ // trait, this ensures that blanket trait methods can't cause this
+ // macro to compile.
+ assert_impl_any_token(previous._static_assertions_impl_any());
+ };
};
}
@@ -163,7 +218,7 @@
///
/// Note that the combination of all provided traits is required to not be
/// implemented. If you want to check that none of multiple traits are
-/// implemented you should invoke [`assert_impl_not_any!`] instead.
+/// implemented you should invoke [`assert_not_impl_any!`] instead.
///
/// # Examples
///
@@ -171,7 +226,7 @@
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_impl_not_all!(u32: From<u16>, Into<usize>);
+/// assert_not_impl_all!(u32: From<u16>, Into<usize>);
/// ```
///
/// The following example fails to compile since `u32` can be converted into
@@ -179,7 +234,7 @@
///
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_impl_not_all!(u32: Into<u64>);
+/// assert_not_impl_all!(u32: Into<u64>);
/// ```
///
/// The following compiles because [`Cell`] is not both [`Sync`] _and_ [`Send`]:
@@ -188,7 +243,7 @@
/// # #[macro_use] extern crate static_assertions; fn main() {}
/// use std::cell::Cell;
///
-/// assert_impl_not_all!(Cell<u32>: Sync, Send);
+/// assert_not_impl_all!(Cell<u32>: Sync, Send);
/// ```
///
/// But it is [`Send`], so this fails to compile:
@@ -196,33 +251,38 @@
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions; fn main() {}
/// # std::cell::Cell;
-/// assert_impl_not_all!(Cell<u32>: Send);
+/// assert_not_impl_all!(Cell<u32>: Send);
/// ```
///
/// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
/// [`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
-/// [`assert_impl_not_any!`]: macro.assert_impl_not_any.html
+/// [`assert_not_impl_any!`]: macro.assert_not_impl_any.html
/// [`Cell`]: https://doc.rust-lang.org/std/cell/struct.Cell.html
/// [blanket]: https://doc.rust-lang.org/book/ch10-02-traits.html#using-trait-bounds-to-conditionally-implement-methods
-#[macro_export(local_inner_macros)]
-macro_rules! assert_impl_not_all {
- ($ty:ty: $($traits:path),+ $(,)?) => {
- assert_impl!($ty: !( $( ($traits) )&+ ));
- };
-}
-
-/// Asserts that the type does **not** implement _all_ of the given traits.
-///
-/// This macro has been deprecated in favor of
-/// [`assert_impl_not_all!`](macro.assert_impl_not_all.html).
-#[deprecated(
- since = "1.2.0",
- note = "Please use the 'assert_impl_not_all' macro instead"
-)]
-#[macro_export(local_inner_macros)]
+#[macro_export]
macro_rules! assert_not_impl_all {
- ($($t:tt)*) => {
- assert_impl_not_all!($($t)*);
+ ($x:ty: $($t:path),+ $(,)?) => {
+ const _: fn() = || {
+ // Generic trait with a blanket impl over `()` for all types.
+ trait AmbiguousIfImpl<A> {
+ // Required for actually being able to reference the trait.
+ fn some_item() {}
+ }
+
+ impl<T: ?Sized> AmbiguousIfImpl<()> for T {}
+
+ // Used for the specialized impl when *all* traits in
+ // `$($t)+` are implemented.
+ #[allow(dead_code)]
+ struct Invalid;
+
+ impl<T: ?Sized $(+ $t)+> AmbiguousIfImpl<Invalid> for T {}
+
+ // If there is only one specialized trait impl, type inference with
+ // `_` can be resolved and this can compile. Fails to compile if
+ // `$x` implements `AmbiguousIfImpl<Invalid>`.
+ let _ = <$x as AmbiguousIfImpl<_>>::some_item;
+ };
};
}
@@ -233,7 +293,7 @@
///
/// This macro causes a compilation failure if any of the provided individual
/// traits are implemented for the type. If you want to check that a combination
-/// of traits is not implemented you should invoke [`assert_impl_not_all!`]
+/// of traits is not implemented you should invoke [`assert_not_impl_all!`]
/// instead. For single traits both macros behave the same.
///
/// # Examples
@@ -243,14 +303,14 @@
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_impl_not_any!(u32: Into<usize>, Into<u8>);
+/// assert_not_impl_any!(u32: Into<usize>, Into<u8>);
/// ```
///
/// This is also good for simple one-off cases:
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_impl_not_any!(&'static mut u8: Copy);
+/// assert_not_impl_any!(&'static mut u8: Copy);
/// ```
///
/// The following example fails to compile since `u32` can be converted into
@@ -258,128 +318,39 @@
///
/// ```compile_fail
/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_impl_not_any!(u32: Into<u64>, Into<u16>);
+/// assert_not_impl_any!(u32: Into<u64>, Into<u16>);
/// ```
///
/// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
/// [`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
-/// [`assert_impl_not_all!`]: macro.assert_impl_not_all.html
+/// [`assert_not_impl_all!`]: macro.assert_not_impl_all.html
/// [blanket]: https://doc.rust-lang.org/book/ch10-02-traits.html#using-trait-bounds-to-conditionally-implement-methods
-#[macro_export(local_inner_macros)]
-macro_rules! assert_impl_not_any {
- ($ty:ty: $($traits:path),+ $(,)?) => {
- assert_impl!($ty: !( $( ($traits) )|+ ));
- };
-}
-
-/// Asserts that the type does **not** implement _any_ of the given traits.
-///
-/// This macro has been deprecated in favor of
-/// [`assert_impl_not_any!`](macro.assert_impl_not_any.html).
-#[deprecated(
- since = "1.2.0",
- note = "Please use the 'assert_impl_not_any' macro instead"
-)]
-#[macro_export(local_inner_macros)]
+#[macro_export]
macro_rules! assert_not_impl_any {
- ($($t:tt)*) => {
- assert_impl_not_any!($($t)*);
- };
-}
-
-/// Asserts that the type implements a logical trait expression.
-///
-/// This macro causes a compilation failure if the expression is not satisfied.
-///
-/// See [`does_impl!`](macro.does_impl.html) for simply getting a [`bool`] from
-/// this condition without asserting it.
-///
-/// # Syntax
-///
-/// ```skip
-/// assert_impl!(<type>: <trait_expr>);
-/// assert_impl!(for(<type>: <bounds>) <type>: <trait_expr>);
-/// ```
-///
-/// where:
-///
-/// - `<type>` is a type (that must not depend on a generic parameter)
-///
-/// - `<trait_expr>` is an expression made out of trait names, combined with `!`
-/// for negation, `&` for conjunction, `|` for disjunction and parentheses for
-/// grouping.
-///
-/// - `<bounds>` is a trait bounds expression.
-///
-/// For technical reasons:
-///
-/// - Traits (like `Into<u8>`) that are not a single identifier must be
-/// surrounded by parentheses.
-///
-/// - The usual operator priority is not respected: `x & y | z` is parsed as
-/// `x & (y | z)`.
-///
-/// # Examples
-///
-/// If `u32` were to implement `Into` conversions for `usize` _and_ for `u8`,
-/// the following would fail to compile:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_impl!(u32: !((Into<usize>) & (Into<u8>)));
-/// ```
-///
-/// Check that a type is [`Send`] but not [`Sync`].
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// use std::cell::Cell;
-///
-/// assert_impl!(Cell<u32>: Send & !Sync);
-/// ```
-///
-/// Check simple one-off cases:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_impl!(&'static mut u8: !Copy);
-/// ```
-///
-/// Check that a type is _always_ [`Clone`] even when its parameter isn't:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// use std::rc::Rc;
-///
-/// assert_impl!(for(T) Rc<T>: Clone);
-/// ```
-///
-/// The following example fails to compile since `u64` cannot be converted into
-/// either `u32` or `u16`:
-///
-/// ```compile_fail
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_impl!(u64: (Into<u32>) | (Into<u16>));
-/// ```
-///
-/// [`bool`]: https://doc.rust-lang.org/std/primitive.bool.html
-/// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
-/// [`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
-/// [`Clone`]: https://doc.rust-lang.org/std/clone/trait.Clone.html
-#[macro_export(local_inner_macros)]
-macro_rules! assert_impl {
- (for($($generic:tt)*) $ty:ty: $($rest:tt)*) => {
- const _: () = {
- fn assert_impl<$($generic)*>() {
- // Construct an expression using `True`/`False` and their
- // operators, that corresponds to the provided expression.
- let _: $crate::True = $crate::_does_impl!($ty: $($rest)*);
+ ($x:ty: $($t:path),+ $(,)?) => {
+ const _: fn() = || {
+ // Generic trait with a blanket impl over `()` for all types.
+ trait AmbiguousIfImpl<A> {
+ // Required for actually being able to reference the trait.
+ fn some_item() {}
}
+
+ impl<T: ?Sized> AmbiguousIfImpl<()> for T {}
+
+ // Creates multiple scoped `Invalid` types for each trait `$t`, over
+ // which a specialized `AmbiguousIfImpl<Invalid>` is implemented for
+ // every type that implements `$t`.
+ $({
+ #[allow(dead_code)]
+ struct Invalid;
+
+ impl<T: ?Sized + $t> AmbiguousIfImpl<Invalid> for T {}
+ })+
+
+ // If there is only one specialized trait impl, type inference with
+ // `_` can be resolved and this can compile. Fails to compile if
+ // `$x` implements any `AmbiguousIfImpl<Invalid>`.
+ let _ = <$x as AmbiguousIfImpl<_>>::some_item;
};
};
- ($ty:ty: $($rest:tt)*) => {
- // Construct an expression using `True`/`False` and their operators,
- // that corresponds to the provided expression.
- const _: $crate::True = $crate::_does_impl!($ty: $($rest)*);
- };
}
diff --git a/src/assert_trait.rs b/src/assert_trait.rs
index 5c87ce6..c231492 100644
--- a/src/assert_trait.rs
+++ b/src/assert_trait.rs
@@ -36,10 +36,20 @@
/// [`PartialOrd`]: https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html
/// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
/// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
-#[macro_export(local_inner_macros)]
+#[macro_export]
macro_rules! assert_trait_sub_all {
($sub:path: $($super:path),+ $(,)?) => {
- assert_impl!(for(T: $sub) T: $( ($super) )&+);
+ const _: () = {
+ // One scope per super-trait.
+ $({
+ #[allow(non_camel_case_types)]
+ trait __Impl_Implication: $super {}
+
+ // Can only be implemented for `$sub` types if `$super` is
+ // also implemented.
+ impl<T: $sub> __Impl_Implication for T {}
+ })+
+ };
};
}
@@ -93,47 +103,3 @@
$(assert_trait_sub_all!($sub: $super);)+
};
}
-
-/// Asserts that the trait is a child of one or more of the other traits.
-///
-/// Related:
-/// - [`assert_impl_any!`]
-///
-/// # Examples
-///
-/// All types that implement [`Copy`] must implement [`Clone`]:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_trait_sub_any!(Copy: Clone);
-/// ```
-///
-/// All types that implement [`Ord`] must implement [`Eq`], but don't have to implement [`Clone`]:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_trait_sub_any!(Ord: Eq, Clone);
-/// ```
-///
-/// The following example fails to compile because neither [`Eq`] nor [`Clone`] are required for
-/// [`PartialOrd`]:
-///
-/// ```compile_fail
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// assert_trait_sub_any!(PartialOrd: Eq, Clone);
-/// ```
-///
-/// [`assert_impl_any!`]: macro.assert_impl_any.html
-///
-/// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
-/// [`Clone`]: https://doc.rust-lang.org/std/clone/trait.Clone.html
-/// [`Ord`]: https://doc.rust-lang.org/std/cmp/trait.Ord.html
-/// [`PartialOrd`]: https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html
-/// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
-/// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
-#[macro_export(local_inner_macros)]
-macro_rules! assert_trait_sub_any {
- ($sub:path: $($super:path),+ $(,)?) => {
- assert_impl!(for(T: $sub) T: $( ($super) )|+);
- };
-}
diff --git a/src/bool.rs b/src/bool.rs
deleted file mode 100644
index 296159f..0000000
--- a/src/bool.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-#[derive(Clone, Copy)]
-pub struct True;
-#[derive(Clone, Copy)]
-pub struct False;
-
-impl True {
- pub const fn not(&self) -> &'static False {
- &False
- }
- pub const fn and<'a, T>(&self, other: &'a T) -> &'a T {
- other
- }
- pub const fn or<T>(&self, _: &T) -> &'static True {
- &True
- }
- pub const fn value(&self) -> bool {
- true
- }
-}
-
-impl False {
- pub const fn not(&self) -> &'static True {
- &True
- }
- pub const fn and<T>(&self, _: &T) -> &'static False {
- &False
- }
- pub const fn or<'a, T>(&self, other: &'a T) -> &'a T {
- other
- }
- pub const fn value(&self) -> bool {
- false
- }
-}
-
-pub trait ToBool: Sized {
- type Bool: Sized;
- const TO_BOOL: Self::Bool;
-}
-
-impl ToBool for [(); 0] {
- type Bool = False;
- const TO_BOOL: Self::Bool = False;
-}
-
-impl ToBool for [(); 1] {
- type Bool = True;
- const TO_BOOL: Self::Bool = True;
-}
-
-/// Converts a `const bool` to a type-level boolean.
-#[doc(hidden)]
-#[macro_export]
-macro_rules! _to_bool {
- ($x:expr) => {{
- const X: bool = $x;
- <[(); X as usize] as $crate::_bool::ToBool>::TO_BOOL
- }};
-}
diff --git a/src/const_assert.rs b/src/const_assert.rs
index 39ad3eb..16ae4a6 100644
--- a/src/const_assert.rs
+++ b/src/const_assert.rs
@@ -48,26 +48,23 @@
/// ```
///
/// [static_assert]: http://en.cppreference.com/w/cpp/language/static_assert
-#[macro_export(local_inner_macros)]
+#[macro_export]
macro_rules! const_assert {
($x:expr $(,)?) => {
- const _: $crate::True = _to_bool!($x);
+ #[allow(unknown_lints, eq_op)]
+ const _: [(); 0 - !{ const ASSERT: bool = $x; ASSERT } as usize] = [];
};
}
/// Asserts that constants are equal in value.
///
-/// Use [`const_assert_eq_usize!`](macro.const_assert_eq_usize.html) for better
-/// error messages when asserting
-/// [`usize`](https://doc.rust-lang.org/std/primitive.usize.html) equality.
-///
/// # Examples
///
/// This works as a shorthand for `const_assert!(a == b)`:
///
/// ```
/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// const TWO: i32 = 2;
+/// const TWO: usize = 2;
///
/// const_assert_eq!(TWO * TWO, TWO + TWO);
/// ```
@@ -80,22 +77,8 @@
/// ```
#[macro_export(local_inner_macros)]
macro_rules! const_assert_eq {
- ($x:expr, $($y:expr),+ $(,)?) => {
- const_assert!($($x == $y)&&+);
- };
-}
-
-/// Asserts that constants of type
-/// [`usize`](https://doc.rust-lang.org/std/primitive.usize.html) are equal in
-/// value.
-///
-/// This is equivalent to [`const_assert_eq!`](macro.const_assert_eq.html) but
-/// allows for inspecting the values in error messages.
-#[macro_export]
-macro_rules! const_assert_eq_usize {
- ($x:expr, $($y:expr),+ $(,)?) => {
- // Assigned instance must match the annotated type or else it will fail.
- $(const _: [(); $x] = [(); $y];)+
+ ($x:expr, $y:expr $(,)?) => {
+ const_assert!($x == $y);
};
}
@@ -120,59 +103,7 @@
/// ```
#[macro_export(local_inner_macros)]
macro_rules! const_assert_ne {
- ($x:expr, $($y:expr),+ $(,)?) => {
- const_assert!($($x != $y)&&+);
- };
-}
-
-/// Asserts that constants are less than each other.
-#[macro_export(local_inner_macros)]
-macro_rules! const_assert_lt {
- ($x:expr, $($y:expr),+ $(,)?) => {
- const_assert_lt!(@build $x, $($y),+);
- };
- (@build $x:expr) => {};
- (@build $x:expr, $($y:expr),+) => {
- const_assert!($x < _head!($($y),+));
- const_assert_lt!(@build $($y),+);
- };
-}
-
-/// Asserts that constants are less than or equal to each other.
-#[macro_export(local_inner_macros)]
-macro_rules! const_assert_le {
- ($x:expr, $($y:expr),+ $(,)?) => {
- const_assert_le!(@build $x, $($y),+);
- };
- (@build $x:expr) => {};
- (@build $x:expr, $($y:expr),+) => {
- const_assert!($x <= _head!($($y),+));
- const_assert_le!(@build $($y),+);
- };
-}
-
-/// Asserts that constants are greater than each other.
-#[macro_export(local_inner_macros)]
-macro_rules! const_assert_gt {
- ($x:expr, $($y:expr),+ $(,)?) => {
- const_assert_gt!(@build $x, $($y),+);
- };
- (@build $x:expr) => {};
- (@build $x:expr, $($y:expr),+) => {
- const_assert!($x > _head!($($y),+));
- const_assert_gt!(@build $($y),+);
- };
-}
-
-/// Asserts that constants are less than or equal to each other.
-#[macro_export(local_inner_macros)]
-macro_rules! const_assert_ge {
- ($x:expr, $($y:expr),+ $(,)?) => {
- const_assert_ge!(@build $x, $($y),+);
- };
- (@build $x:expr) => {};
- (@build $x:expr, $($y:expr),+) => {
- const_assert!($x >= _head!($($y),+));
- const_assert_ge!(@build $($y),+);
+ ($x:expr, $y:expr $(,)?) => {
+ const_assert!($x != $y);
};
}
diff --git a/src/does_impl.rs b/src/does_impl.rs
deleted file mode 100644
index f2d35fe..0000000
--- a/src/does_impl.rs
+++ /dev/null
@@ -1,108 +0,0 @@
-/// Returns `true` if the type does implement a logical trait expression.
-///
-/// # Examples
-///
-/// One can mimic `assert_impl!` using this macro:
-///
-/// ```
-/// # #[macro_use] extern crate static_assertions; fn main() {}
-/// const CONDITION: bool = does_impl!(u32: From<u8>);
-///
-/// const_assert!(CONDITION);
-/// ```
-#[macro_export(local_inner_macros)]
-macro_rules! does_impl {
- ($ty:ty: $($trait_expr:tt)+) => {
- _does_impl!($ty: $($trait_expr)+).value()
- };
-}
-
-/// Returns `True` or `False` depending on whether the given type implements the
-/// given trait boolean expression. Can be used in const contexts if it doesn't
-/// depend on outer generic parameters.
-///
-/// This is the core of `assert_impl`.
-#[doc(hidden)]
-#[macro_export(local_inner_macros)]
-macro_rules! _does_impl {
- ($ty:ty: $($rest:tt)*) => {{
- #[allow(unused_imports)]
- use $crate::{
- _bool::{True, False},
- _core::{marker::PhantomData, ops::Deref},
- };
-
- // Fallback trait that returns false if the type does not implement a
- // given trait.
- trait DoesntImpl {
- const DOES_IMPL: False = False;
- }
- impl<T: ?Sized> DoesntImpl for T {}
-
- // Construct an expression using `True`/`False` and their operators,
- // that corresponds to the provided expression.
- *_does_impl!(@boolexpr($ty,) $($rest)*)
- }};
-
- (@boolexpr($($args:tt)*) ($($expr:tt)*)) => {
- _does_impl!(@boolexpr($($args)*) $($expr)*)
- };
- (@boolexpr($($args:tt)*) !($($expr:tt)*)) => {
- _does_impl!(@boolexpr($($args)*) $($expr)*).not()
- };
- (@boolexpr($($args:tt)*) ($($left:tt)*) | $($right:tt)*) => {{
- let left = _does_impl!(@boolexpr($($args)*) $($left)*);
- let right = _does_impl!(@boolexpr($($args)*) $($right)*);
- left.or(right)
- }};
- (@boolexpr($($args:tt)*) ($($left:tt)*) & $($right:tt)*) => {{
- let left = _does_impl!(@boolexpr($($args)*) $($left)*);
- let right = _does_impl!(@boolexpr($($args)*) $($right)*);
- left.and(right)
- }};
- (@boolexpr($($args:tt)*) !($($left:tt)*) | $($right:tt)*) => {{
- _does_impl!(@boolexpr($($args)*) (!($($left)*)) | $($right)*)
- }};
- (@boolexpr($($args:tt)*) !($($left:tt)*) & $($right:tt)*) => {{
- _does_impl!(@boolexpr($($args)*) (!($($left)*)) & $($right)*)
- }};
- (@boolexpr($($args:tt)*) !$left:ident | $($right:tt)*) => {{
- _does_impl!(@boolexpr($($args)*) !($left) | $($right)*)
- }};
- (@boolexpr($($args:tt)*) !$left:ident & $($right:tt)*) => {{
- _does_impl!(@boolexpr($($args)*) !($left) & $($right)*)
- }};
- (@boolexpr($($args:tt)*) $left:ident | $($right:tt)*) => {
- _does_impl!(@boolexpr($($args)*) ($left) | $($right)*)
- };
- (@boolexpr($($args:tt)*) $left:ident & $($right:tt)*) => {{
- _does_impl!(@boolexpr($($args)*) ($left) & $($right)*)
- }};
- (@boolexpr($($args:tt)*) !$expr:ident) => {
- _does_impl!(@boolexpr($($args)*) !($expr))
- };
- (@boolexpr($($args:tt)*) !$expr:path) => {
- _does_impl!(@boolexpr($($args)*) !($expr))
- };
- (@boolexpr($($args:tt)*) $expr:ident) => {
- _does_impl!(@base($($args)*) $expr)
- };
- (@boolexpr($($args:tt)*) $expr:path) => {
- _does_impl!(@base($($args)*) $expr)
- };
-
- (@base($ty:ty, $($args:tt)*) $($trait:tt)*) => {{
- // Base case: computes whether `ty` implements `trait`.
- struct Wrapper<T: ?Sized>(PhantomData<T>);
-
- #[allow(dead_code)]
- impl<T: ?Sized + $($trait)*> Wrapper<T> {
- const DOES_IMPL: True = True;
- }
-
- // If `$type: $trait`, the `_does_impl` inherent method on `Wrapper`
- // will be called, and return `True`. Otherwise, the trait method will
- // be called, which returns `False`.
- &<Wrapper<$ty>>::DOES_IMPL
- }};
-}
diff --git a/src/lib.rs b/src/lib.rs
index df47529..d9f1523 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,8 +4,8 @@
//! <a href="https://crates.io/crates/static_assertions">
//! <img src="https://img.shields.io/crates/d/static_assertions.svg" alt="Downloads">
//! </a>
-//! <a href="https://github.com/nvzqz/static-assertions-rs/actions?query=workflow%3ACI">
-//! <img src="https://github.com/nvzqz/static-assertions-rs/workflows/CI/badge.svg" alt="Build Status">
+//! <a href="https://travis-ci.org/nvzqz/static-assertions-rs">
+//! <img src="https://travis-ci.org/nvzqz/static-assertions-rs.svg?branch=master" alt="Build Status">
//! </a>
//! <img src="https://img.shields.io/badge/rustc-^1.37.0-blue.svg" alt="rustc ^1.37.0">
//! <br><br>
@@ -32,7 +32,6 @@
//! and this to your crate root (`main.rs` or `lib.rs`):
//!
//! ```
-//! # #[allow(unused_imports)]
//! #[macro_use]
//! extern crate static_assertions;
//! # fn main() {}
@@ -47,20 +46,6 @@
//! sa::const_assert!(true);
//! ```
//!
-//! ## Procedural Extensions
-//!
-//! As an extension crate [`proc_static_assertions`] adds a number of new
-//! assertions to this. These are implemented as [procedural macros], hence the
-//! "proc" prefix. As a result, they have a bit more visibility over what's
-//! being asserted over than normal macros would.
-//!
-//! It can be enabled via the `proc` feature flag in your [`Cargo.toml`]:
-//!
-//! ```toml
-//! [dependencies]
-//! static_assertions = { version = "1.1.0", features = ["proc"] }
-//! ```
-//!
//! # Examples
//!
//! Very thorough examples are provided in the docs for
@@ -85,61 +70,31 @@
//! <img src="https://buymecoffee.intm.org/img/button-paypal-white.png" alt="Buy me a coffee" height="35">
//! </a>
//!
-//! [`proc_static_assertions`]: https://docs.rs/proc_static_assertions
-//! [procedural macros]: https://doc.rust-lang.org/book/ch19-06-macros.html#procedural-macros-for-generating-code-from-attributes
//! [Rust 1.37]: https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html
//! [2018]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#rust-2018
//! [crate]: https://crates.io/crates/static_assertions
//! [compile-time]: https://en.wikipedia.org/wiki/Compile_time
//! [`Cargo.toml`]: https://doc.rust-lang.org/cargo/reference/manifest.html
-#![deny(missing_docs, unused_macros)]
-#![doc(
- html_root_url = "https://docs.rs/static_assertions/1.1.0",
- html_logo_url = "https://raw.githubusercontent.com/nvzqz/static-assertions-rs/assets/Icon.png",
- test(attr(deny(warnings), allow(dead_code)))
-)]
+#![doc(html_root_url = "https://docs.rs/static_assertions/1.1.0")]
+#![doc(html_logo_url = "https://raw.githubusercontent.com/nvzqz/static-assertions-rs/assets/Icon.png")]
+
#![no_std]
+#![deny(unused_macros)]
+
#[cfg(android_dylib)]
extern crate std;
-#[cfg(feature = "proc_static_assertions")]
-extern crate proc_static_assertions;
-#[cfg(feature = "proc_static_assertions")]
-pub use proc_static_assertions::assert;
-
-// This module should never be used publicly and is not part of this crate's
-// semver requirements.
#[doc(hidden)]
pub extern crate core as _core;
-mod assert_align;
mod assert_cfg;
+mod assert_eq_align;
+mod assert_eq_size;
mod assert_fields;
mod assert_impl;
mod assert_obj_safe;
-mod assert_size;
mod assert_trait;
mod assert_type;
mod const_assert;
-mod does_impl;
-
-// Utility macros.
-//
-// These macros should also never be used publicly and are not part of this
-// crate's semver requirements.
-mod util;
-
-// Type-level booleans.
-//
-// This module should never be used publicly and is not part of this crate's
-// semver requirements.
-#[doc(hidden)]
-#[path = "bool.rs"]
-pub mod _bool;
-
-// These types should also never be used publicly and are not part of this
-// crate's semver requirements.
-#[doc(hidden)]
-pub use _bool::{False, True};
diff --git a/src/util.rs b/src/util.rs
deleted file mode 100644
index 17dbe79..0000000
--- a/src/util.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-#[doc(hidden)]
-#[macro_export]
-macro_rules! _head {
- ($head:expr $(, $tail:expr)* $(,)?) => {
- $head
- };
-}
diff --git a/tests/const.rs b/tests/const.rs
deleted file mode 100644
index cdd2d70..0000000
--- a/tests/const.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-#![no_std]
-#![deny(unsafe_code)]
-
-#[macro_use]
-extern crate static_assertions;
-
-const_assert!(true && (true != false));
-const_assert!((true && true) != false);
-const_assert_eq!(false, false);
-
-#[allow(dead_code)]
-const FIVE: usize = 5;
-
-const_assert!(FIVE * 2 == 10);
-const_assert!(FIVE > 2);
diff --git a/tests/eq_size.rs b/tests/eq_size.rs
deleted file mode 100644
index 3317b94..0000000
--- a/tests/eq_size.rs
+++ /dev/null
@@ -1,113 +0,0 @@
-#![no_std]
-#![deny(unsafe_code)]
-
-#[macro_use]
-extern crate static_assertions;
-
-assert_size_eq!(u8, u8, (u8,), [u8; 1]);
-
-mod assoc_type {
- trait Trait {
- type AssocItem: ?Sized;
- }
-
- impl<T: ?Sized> Trait for T {
- type AssocItem = Self;
- }
-
- #[allow(dead_code)]
- struct Value;
-
- assert_size_eq!(<Value as Trait>::AssocItem, Value);
-
- // TODO: Is this possible?
- // pub fn test<T: Trait>() {
- // assert_size_eq!(<T as Trait>::AssocItem, T);
- // }
-}
-
-// Placed in separate module so that DropCounter's fields are private
-mod dc {
- /// A type that acts like somewhat of a reference counter.
- pub struct DropCounter<'a> {
- count: &'a mut i32,
- }
-
- impl<'a> DropCounter<'a> {
- pub fn new(count: &'a mut i32) -> DropCounter<'a> {
- *count += 1;
- DropCounter { count }
- }
-
- pub fn count(&self) -> i32 {
- *self.count
- }
- }
-
- impl<'a> Drop for DropCounter<'a> {
- fn drop(&mut self) {
- *self.count -= 1
- }
- }
-}
-use dc::*;
-
-/// A type that panics on drop.
-#[allow(dead_code)]
-struct PanicDrop<T>(T);
-
-impl<T> Drop for PanicDrop<T> {
- fn drop(&mut self) {
- panic!("Dropped!");
- }
-}
-
-#[test]
-fn test_eq_size() {
- assert_size_eq!([u8; 2], u16);
- assert_size_eq!([u8; 2], u16, (u8, u8));
- assert_size_eq!([u8; 4], u32, (u16, u8, u8), (u16, u16));
-
- assert_size_eq_val!([0u8; 2], 0u16);
- assert_size_eq_val!([0u8; 2], 0u16, (0u8, 0u8));
- assert_size_eq_val!([0u8; 4], 0u32, (0u16, 0u8, 0u8), (0u16, 0u16));
-
- #[deny(unused_unsafe)]
- {
- assert_size_eq!(u8, u8);
- assert_size_eq_val!(0u8, 0u8);
- }
-
- let x = &mut 0;
- assert_size_eq_ptr!(x, &0);
- *x = 20;
- assert_size_eq_ptr!(x, &0);
-
- // Should fail to compile (un-comment to test manually):
- // assert_size_eq!(u8, u16);
- // assert_size_eq_val!(0u8, 0u16);
-}
-
-#[test]
-fn test_eq_size_no_drop() {
- assert_size_eq!(u32, PanicDrop<u32>);
- assert_size_eq!(PanicDrop<u32>, u32);
- assert_size_eq!(PanicDrop<u32>, PanicDrop<u32>);
-}
-
-#[test]
-fn test_eq_size_drop_count() {
- let mut count = 0;
- {
- let dc = DropCounter::new(&mut count);
- assert_eq!(dc.count(), 1);
- assert_size_eq_val!(dc, 0usize);
- assert_eq!(dc.count(), 1);
- assert_size_eq_val!(dc, 0usize, dc);
- assert_eq!(dc.count(), 1);
- }
- assert_eq!(count, 0);
-
- assert_size_eq_val!(DropCounter::new(&mut count), 0usize);
- assert_eq!(count, 0);
-}
diff --git a/tests/fields.rs b/tests/fields.rs
deleted file mode 100644
index c465475..0000000
--- a/tests/fields.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-#![no_std]
-#![deny(unsafe_code)]
-
-#[macro_use]
-extern crate static_assertions;
-
-#[allow(dead_code)]
-enum Foo {
- A { x: u8, y: u8 },
- B(u8),
-}
-
-assert_fields!(Foo::A: x);
-assert_fields!(Foo::A: x, x);
-assert_fields!(Foo::A: x, y, x);
-
-// TODO: Make tuple field access possible
-// assert_fields!(Foo::B, 0);
-
-mod m {
- #[allow(dead_code)]
- pub struct Bar<T: ?Sized> {
- pub nul: (),
- pub inner: T,
- }
-}
-
-#[allow(dead_code)]
-use m::Bar as Baz;
-
-assert_fields!(m::Bar<str>: inner, nul);
-assert_fields!(Baz<dyn Send>: inner, nul);
diff --git a/tests/obj_safe.rs b/tests/obj_safe.rs
deleted file mode 100644
index 97847b2..0000000
--- a/tests/obj_safe.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-#![no_std]
-#![deny(unsafe_code)]
-
-#[macro_use]
-extern crate static_assertions;
-
-assert_obj_safe!(core::fmt::Debug, Send, Sync);
-
-trait ObjSafe {}
-assert_obj_safe!(ObjSafe);
diff --git a/tests/proc_size.rs b/tests/proc_size.rs
deleted file mode 100644
index b62a36f..0000000
--- a/tests/proc_size.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-#![cfg(feature = "proc")]
-
-#[macro_use]
-extern crate static_assertions;
-
-#[assert(size == 4, align == 4)]
-struct Foo {
- value: i32,
-}
diff --git a/tests/trait_impl.rs b/tests/trait_impl.rs
deleted file mode 100644
index 2a6fffd..0000000
--- a/tests/trait_impl.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-#![no_std]
-#![deny(unsafe_code)]
-
-#[macro_use]
-extern crate static_assertions;
-
-use core::ops::Range;
-
-trait Tri<A: ?Sized, B: ?Sized, C: ?Sized> {}
-
-impl<T, A: ?Sized, B: ?Sized, C: ?Sized> Tri<A, B, C> for T {}
-
-assert_impl_all!(
- u64: Tri<[&'static u8], dyn Tri<dyn Send, dyn Sync, str>, (u16, u16)>
-);
-assert_impl_all!(u8: Send, Sync);
-assert_impl_all!(&'static [u8]: IntoIterator<Item=&'static u8>);
-assert_impl_all!(Range<u8>: Iterator<Item=u8>);
-assert_impl_all!([u8]: Send, Sync, AsRef<[u8]>);
-assert_impl_all!(str: Send, Sync, AsRef<[u8]>,);
-
-assert_impl_any!((): Send, Sync);
-assert_impl_any!((): Send, From<u8>);
-assert_impl_any!((): From<u8>, From<u16>, Send);
-
-#[allow(dead_code)]
-struct Foo;
-
-trait A {}
-trait B {}
-trait C {}
-
-impl B for Foo {}
-
-assert_impl_one!(Foo: A, B);
-assert_impl_one!(Foo: B, A);
-assert_impl_one!(Foo: B, C);
-assert_impl_one!(Foo: C, B);
-assert_impl_one!(Foo: A, B, C);
-assert_impl_one!(Foo: B, C, A);
-assert_impl_one!(Foo: C, A, B);
-
-#[derive(Clone)]
-struct Test;
-
-assert_impl!(u8: (From<u16>) | (Into<u16>));
-assert_impl!((): (From<u8>) | (From<u16>) | Send);
-assert_impl!((): (!From<u8>) & !(From<u16>) & Send);
-assert_impl!((): Copy | Clone);
-assert_impl!((): Copy & Clone);
-assert_impl!(Test: Copy | Clone);
-assert_impl!(Test: !Copy | Clone);
-assert_impl!(Test: !Copy & Clone);
-assert_impl!(Test: !Copy & (Clone));
-assert_impl!(Test: !(Copy) & Clone);
-assert_impl!(Test: !(!Clone));
-assert_impl!(Test: !(Copy) & !(!Clone));
-assert_impl!(Test: !(Copy & Clone));
-assert_impl!(str: !Copy & !Clone);
-
-#[derive(Clone)]
-struct Box<T>(T);
-
-assert_impl!(for(T: Clone) Box<T>: Clone);
-assert_impl!(for(T: Clone + Send) Box<T>: Clone & Send);
-assert_impl!(for(T) Box<T>: (From<T>) & (Into<T>));
-
-assert_impl!(for(T) PhantomData<T>: Clone);
-assert_impl!(for(T: Copy) T: Clone);
-assert_impl!(for(T: ?Sized) T: Clone | !Clone);
-assert_impl!(for('a, T: 'a) &'a mut T: !Copy);
diff --git a/tests/type_eq.rs b/tests/type_eq.rs
deleted file mode 100644
index e8036d7..0000000
--- a/tests/type_eq.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-#![no_std]
-#![deny(unsafe_code)]
-
-#[macro_use]
-extern crate static_assertions;
-
-assert_type_eq_all!([u8], [u8]);
-
-#[allow(dead_code)]
-type X = u8;
-
-#[allow(unused_parens)]
-mod m {
- assert_type_eq_all!(super::X, u8, (super::X));
-}
diff --git a/tests/type_ne.rs b/tests/type_ne.rs
deleted file mode 100644
index 3adfef0..0000000
--- a/tests/type_ne.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-#![no_std]
-#![deny(unsafe_code)]
-
-#[macro_use]
-extern crate static_assertions;
-
-assert_type_ne_all!(u8, u16, u32);