summaryrefslogtreecommitdiffstats
path: root/vendor/static_assertions/src/assert_cfg.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /vendor/static_assertions/src/assert_cfg.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/static_assertions/src/assert_cfg.rs')
-rw-r--r--vendor/static_assertions/src/assert_cfg.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/static_assertions/src/assert_cfg.rs b/vendor/static_assertions/src/assert_cfg.rs
new file mode 100644
index 000000000..24282c1f3
--- /dev/null
+++ b/vendor/static_assertions/src/assert_cfg.rs
@@ -0,0 +1,49 @@
+/// Asserts that a given configuration is set.
+///
+/// # Examples
+///
+/// A project will simply fail to compile if the given configuration is not set.
+///
+/// ```
+/// # #[macro_use] extern crate static_assertions; fn main() {}
+/// // We're not masochists
+/// # #[cfg(not(target_pointer_width = "16"))] // Just in case
+/// assert_cfg!(not(target_pointer_width = "16"));
+/// ```
+///
+/// If a project does not support a set of configurations, you may want to
+/// report why. There is the option of providing a compile error message string:
+///
+/// ```
+/// # #[macro_use] extern crate static_assertions; fn main() {}
+/// # #[cfg(any(unix, windows))]
+/// assert_cfg!(any(unix, windows), "There is only support for Unix or Windows");
+///
+/// // User needs to specify a database back-end
+/// # #[cfg(target_pointer_width = "0")] // Impossible
+/// assert_cfg!(all(not(all(feature = "mysql", feature = "mongodb")),
+/// any( feature = "mysql", feature = "mongodb")),
+/// "Must exclusively use MySQL or MongoDB as database back-end");
+/// ```
+///
+/// Some configurations are impossible. For example, we can't be compiling for
+/// both macOS _and_ Windows simultaneously:
+///
+/// ```compile_fail
+/// # #[macro_use] extern crate static_assertions; fn main() {}
+/// assert_cfg!(all(target_os = "macos",
+/// target_os = "windows"),
+/// "No, that's not how it works! ಠ_ಠ");
+/// ```
+#[macro_export]
+macro_rules! assert_cfg {
+ () => {};
+ ($($cfg:meta)+, $msg:expr $(,)?) => {
+ #[cfg(not($($cfg)+))]
+ compile_error!($msg);
+ };
+ ($($cfg:tt)*) => {
+ #[cfg(not($($cfg)*))]
+ compile_error!(concat!("Cfg does not pass: ", stringify!($($cfg)*)));
+ };
+}