mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +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"
|
unicode-xid = "0.1.0"
|
||||||
text_unit = "0.1.2"
|
text_unit = "0.1.2"
|
||||||
itertools = "0.7.5"
|
itertools = "0.7.5"
|
||||||
|
drop_bomb = "0.1.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
testutils = { path = "./tests/testutils" }
|
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 itertools;
|
||||||
extern crate text_unit;
|
extern crate text_unit;
|
||||||
extern crate unicode_xid;
|
extern crate unicode_xid;
|
||||||
|
extern crate drop_bomb;
|
||||||
|
|
||||||
pub mod algo;
|
pub mod algo;
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
|
@ -31,7 +32,6 @@ mod lexer;
|
||||||
mod parser_api;
|
mod parser_api;
|
||||||
mod grammar;
|
mod grammar;
|
||||||
mod parser_impl;
|
mod parser_impl;
|
||||||
mod drop_bomb;
|
|
||||||
|
|
||||||
mod syntax_kinds;
|
mod syntax_kinds;
|
||||||
/// Utilities for simple uses of the parser.
|
/// Utilities for simple uses of the parser.
|
||||||
|
|
|
@ -18,24 +18,14 @@ impl TokenSet {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! token_set {
|
macro_rules! token_set {
|
||||||
($($t:ident),*) => {
|
($($t:ident),*) => { TokenSet($(1u128 << ($t as usize))|*) };
|
||||||
TokenSet($(1u128 << ($t as usize))|*)
|
($($t:ident),* ,) => { token_set!($($t),*) };
|
||||||
};
|
|
||||||
|
|
||||||
($($t:ident),* ,) => {
|
|
||||||
token_set!($($t),*)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! token_set_union {
|
macro_rules! token_set_union {
|
||||||
($($ts:expr),*) => {
|
($($ts:expr),*) => { TokenSet($($ts.0)|*) };
|
||||||
TokenSet($($ts.0)|*)
|
($($ts:expr),* ,) => { token_set_union!($($ts),*) };
|
||||||
};
|
|
||||||
|
|
||||||
($($ts:expr),* ,) => {
|
|
||||||
token_set_union!($($ts),*)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Parser` struct provides the low-level API for
|
/// `Parser` struct provides the low-level API for
|
||||||
|
@ -141,7 +131,7 @@ impl Marker {
|
||||||
fn new(pos: u32) -> Marker {
|
fn new(pos: u32) -> Marker {
|
||||||
Marker {
|
Marker {
|
||||||
pos,
|
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