mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 23:24:29 +00:00
drop the bombs
This commit is contained in:
parent
ecd5da5b0c
commit
1954df6336
4 changed files with 7 additions and 37 deletions
|
@ -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" }
|
||||
|
|
|
@ -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<Cow<'static, str>>) -> 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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue