diff --git a/Cargo.toml b/Cargo.toml index d616133528..8af8f825b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "tools", "cli", "libeditor" ] unicode-xid = "0.1.0" text_unit = "0.1.2" itertools = "0.7.5" +drop_bomb = "0.1.4" [dev-dependencies] testutils = { path = "./tests/testutils" } diff --git a/src/drop_bomb.rs b/src/drop_bomb.rs deleted file mode 100644 index 750904a013..0000000000 --- a/src/drop_bomb.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::borrow::Cow; - -pub struct DropBomb { - msg: Cow<'static, str>, - defused: bool, -} - -impl DropBomb { - pub fn new(msg: impl Into>) -> DropBomb { - DropBomb { msg: msg.into(), defused: false } - } - pub fn defuse(&mut self) { self.defused = true } -} - -impl Drop for DropBomb { - fn drop(&mut self) { - if !self.defused && !::std::thread::panicking() { - panic!("{}", self.msg) - } - } -} diff --git a/src/lib.rs b/src/lib.rs index d9572912cc..a7705ab66b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,7 @@ extern crate itertools; extern crate text_unit; extern crate unicode_xid; +extern crate drop_bomb; pub mod algo; pub mod ast; @@ -31,7 +32,6 @@ mod lexer; mod parser_api; mod grammar; mod parser_impl; -mod drop_bomb; mod syntax_kinds; /// Utilities for simple uses of the parser. diff --git a/src/parser_api.rs b/src/parser_api.rs index 3cad91976c..95394e39d0 100644 --- a/src/parser_api.rs +++ b/src/parser_api.rs @@ -18,24 +18,14 @@ impl TokenSet { #[macro_export] macro_rules! token_set { - ($($t:ident),*) => { - TokenSet($(1u128 << ($t as usize))|*) - }; - - ($($t:ident),* ,) => { - token_set!($($t),*) - }; + ($($t:ident),*) => { TokenSet($(1u128 << ($t as usize))|*) }; + ($($t:ident),* ,) => { token_set!($($t),*) }; } #[macro_export] macro_rules! token_set_union { - ($($ts:expr),*) => { - TokenSet($($ts.0)|*) - }; - - ($($ts:expr),* ,) => { - token_set_union!($($ts),*) - }; + ($($ts:expr),*) => { TokenSet($($ts.0)|*) }; + ($($ts:expr),* ,) => { token_set_union!($($ts),*) }; } /// `Parser` struct provides the low-level API for @@ -141,7 +131,7 @@ impl Marker { fn new(pos: u32) -> Marker { Marker { pos, - bomb: DropBomb::new("Marker must be either completed or abandoned") + bomb: DropBomb::new("Marker must be either completed or abandoned"), } }