diff options
Diffstat (limited to 'third_party/rust/new_debug_unreachable')
8 files changed, 154 insertions, 0 deletions
diff --git a/third_party/rust/new_debug_unreachable/.cargo-checksum.json b/third_party/rust/new_debug_unreachable/.cargo-checksum.json new file mode 100644 index 0000000000..6fb70810b9 --- /dev/null +++ b/third_party/rust/new_debug_unreachable/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.lock":"438cea17a96e11f787f827aab8c4fe2d096d75b1db95b5749339b9d2b2554d5b","Cargo.toml":"bcaf0900427df4f1e1f61bfaf99ec22422be14b97432ace1287e52803e9c6f0b","LICENSE-MIT":"f7715d38a3fa1b4ac97c5729740752505a39cb92ee83ab5b102aeb5eaa7cdea4","README.md":"614d60e78bd8c3d8172b2650f86d44c703471dab8a35805736861f09158e5501","examples/simple.rs":"f1fac7f8308469568b601218ea03d213584f0a51b779a3bcb78ecb40ede72483","src/lib.rs":"5a2cbd34e3a52ea1a8e1b31dd34c5ec31ce549fec30f60a0e20b87d8138da416","tests/check.rs":"323e500890599105193b6b07563a2c570ea0cc56342c81670075e5fd2ff467d1"},"package":"e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"}
\ No newline at end of file diff --git a/third_party/rust/new_debug_unreachable/Cargo.lock b/third_party/rust/new_debug_unreachable/Cargo.lock new file mode 100644 index 0000000000..b0732960f5 --- /dev/null +++ b/third_party/rust/new_debug_unreachable/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" + diff --git a/third_party/rust/new_debug_unreachable/Cargo.toml b/third_party/rust/new_debug_unreachable/Cargo.toml new file mode 100644 index 0000000000..079667b5e4 --- /dev/null +++ b/third_party/rust/new_debug_unreachable/Cargo.toml @@ -0,0 +1,26 @@ +# 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] +edition = "2018" +name = "new_debug_unreachable" +version = "1.0.4" +authors = ["Matt Brubeck <mbrubeck@limpet.net>", "Jonathan Reem <jonathan.reem@gmail.com>"] +description = "panic in debug, intrinsics::unreachable() in release (fork of debug_unreachable)" +documentation = "https://docs.rs/new_debug_unreachable" +readme = "README.md" +license = "MIT" +repository = "https://github.com/mbrubeck/rust-debug-unreachable" + +[lib] +name = "debug_unreachable" +path = "src/lib.rs" diff --git a/third_party/rust/new_debug_unreachable/LICENSE-MIT b/third_party/rust/new_debug_unreachable/LICENSE-MIT new file mode 100644 index 0000000000..c8e0f5ec7a --- /dev/null +++ b/third_party/rust/new_debug_unreachable/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2015 Jonathan Reem + +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/third_party/rust/new_debug_unreachable/README.md b/third_party/rust/new_debug_unreachable/README.md new file mode 100644 index 0000000000..b9c8b1e2c4 --- /dev/null +++ b/third_party/rust/new_debug_unreachable/README.md @@ -0,0 +1,42 @@ +# new_debug_unreachable + +> unreachable!() in debug, std::intrinsics::unreachable() in release. + +This is a fork of [`debug_unreachable`](https://crates.io/crates/debug_unreachable). + +## [Documentation](https://docs.rs/new_debug_unreachable) + +## Usage + +Use the crates.io repository; add this to your `Cargo.toml` along +with the rest of your dependencies: + +```toml +[dependencies] +new_debug_unreachable = "1.0" +``` + +In your Rust code, the library name is still `debug_unreachable`: + +```rust +use debug_unreachable::debug_unreachable; + +fn main() { + if 0 > 100 { + // Can't happen! + unsafe { debug_unreachable!() } + } else { + println!("Good, 0 <= 100."); + } +} +``` + +## Author + +[Jonathan Reem](https://medium.com/@jreem) is the original author of debug-unreachable. + +[Matt Brubeck](https://limpet.net/mbrubeck/) is the maintainer of this fork. + +## License + +MIT diff --git a/third_party/rust/new_debug_unreachable/examples/simple.rs b/third_party/rust/new_debug_unreachable/examples/simple.rs new file mode 100644 index 0000000000..7f59438f4c --- /dev/null +++ b/third_party/rust/new_debug_unreachable/examples/simple.rs @@ -0,0 +1,10 @@ +use debug_unreachable::debug_unreachable; + +fn main() { + if 0 > 100 { + // Can't happen! + unsafe { debug_unreachable!() } + } else { + println!("Good, 0 <= 100."); + } +} diff --git a/third_party/rust/new_debug_unreachable/src/lib.rs b/third_party/rust/new_debug_unreachable/src/lib.rs new file mode 100644 index 0000000000..db0f968f0a --- /dev/null +++ b/third_party/rust/new_debug_unreachable/src/lib.rs @@ -0,0 +1,36 @@ +#![deny(missing_docs, warnings)] + +#![no_std] + +//! `panic!()` in debug builds, optimization hint in release. + +#[doc(hidden)] pub mod _internal { pub use core::hint::unreachable_unchecked; } + +#[macro_export] +/// `panic!()` in debug builds, optimization hint in release. +/// +/// Example: +/// +/// ``` +/// use debug_unreachable::debug_unreachable; +/// +/// fn main() { +/// if 0 > 100 { +/// // Can't happen! +/// unsafe { debug_unreachable!() } +/// } else { +/// println!("Good, 0 <= 100."); +/// } +/// } +/// ``` +macro_rules! debug_unreachable { + () => { debug_unreachable!("entered unreachable code") }; + ($e:expr) => { + if cfg!(debug_assertions) { + panic!($e) + } else { + $crate::_internal::unreachable_unchecked() + } + } +} + diff --git a/third_party/rust/new_debug_unreachable/tests/check.rs b/third_party/rust/new_debug_unreachable/tests/check.rs new file mode 100644 index 0000000000..f73552a9a5 --- /dev/null +++ b/third_party/rust/new_debug_unreachable/tests/check.rs @@ -0,0 +1,8 @@ +#[test] +#[should_panic] +#[cfg(debug_assertions)] +fn explodes_in_debug() { + use debug_unreachable::debug_unreachable; + unsafe { debug_unreachable!() } +} + |