diff options
author | Aleksey Kladov <[email protected]> | 2019-01-10 10:04:04 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-10 10:04:04 +0000 |
commit | f72c031eb9a15f25834a7980008db764ff2867a0 (patch) | |
tree | a3560becba476775f18c996293d6d5892e7611f0 | |
parent | 64455ad701c8bce6e35793042f5e2ec177e12f7e (diff) |
implement RefUnwindSafe
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_db/src/loc2id.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/mock.rs | 4 |
4 files changed, 16 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock index eb053a09c..74e9d0e6e 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1024,7 +1024,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1024 | [[package]] | 1024 | [[package]] |
1025 | name = "salsa" | 1025 | name = "salsa" |
1026 | version = "0.9.1" | 1026 | version = "0.9.1" |
1027 | source = "git+https://github.com/matklad/salsa?branch=panic-hooks#add15d83eaa865571cd33e60b2eb611a366ca3ff" | 1027 | source = "git+https://github.com/matklad/salsa?branch=panic-hooks#a17757bbaaadeed4839366745b848d66ac991cd0" |
1028 | dependencies = [ | 1028 | dependencies = [ |
1029 | "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", | 1029 | "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", |
1030 | "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1030 | "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 00d2d5ae9..20e712afe 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -20,7 +20,7 @@ pub use crate::{ | |||
20 | loc2id::LocationIntener, | 20 | loc2id::LocationIntener, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | pub trait BaseDatabase: salsa::Database { | 23 | pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { |
24 | fn check_canceled(&self) -> Cancelable<()> { | 24 | fn check_canceled(&self) -> Cancelable<()> { |
25 | self.salsa_runtime() | 25 | self.salsa_runtime() |
26 | .if_current_revision_is_canceled(Canceled::throw); | 26 | .if_current_revision_is_canceled(Canceled::throw); |
@@ -31,8 +31,7 @@ pub trait BaseDatabase: salsa::Database { | |||
31 | &self, | 31 | &self, |
32 | f: F, | 32 | f: F, |
33 | ) -> Result<T, Canceled> { | 33 | ) -> Result<T, Canceled> { |
34 | let me = panic::AssertUnwindSafe(self); | 34 | panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::<Canceled>() { |
35 | panic::catch_unwind(|| f(me.0)).map_err(|err| match err.downcast::<Canceled>() { | ||
36 | Ok(canceled) => *canceled, | 35 | Ok(canceled) => *canceled, |
37 | Err(payload) => panic::resume_unwind(payload), | 36 | Err(payload) => panic::resume_unwind(payload), |
38 | }) | 37 | }) |
diff --git a/crates/ra_db/src/loc2id.rs b/crates/ra_db/src/loc2id.rs index 254c52629..359cd893d 100644 --- a/crates/ra_db/src/loc2id.rs +++ b/crates/ra_db/src/loc2id.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use std::hash::Hash; | 1 | use std::{panic, hash::Hash}; |
2 | 2 | ||
3 | use parking_lot::Mutex; | 3 | use parking_lot::Mutex; |
4 | use rustc_hash::FxHashMap; | 4 | use rustc_hash::FxHashMap; |
@@ -70,6 +70,15 @@ where | |||
70 | map: Mutex<Loc2IdMap<LOC, ID>>, | 70 | map: Mutex<Loc2IdMap<LOC, ID>>, |
71 | } | 71 | } |
72 | 72 | ||
73 | impl<LOC, ID> panic::RefUnwindSafe for LocationIntener<LOC, ID> | ||
74 | where | ||
75 | ID: ArenaId + Clone, | ||
76 | LOC: Clone + Eq + Hash, | ||
77 | ID: panic::RefUnwindSafe, | ||
78 | LOC: panic::RefUnwindSafe, | ||
79 | { | ||
80 | } | ||
81 | |||
73 | impl<LOC, ID> Default for LocationIntener<LOC, ID> | 82 | impl<LOC, ID> Default for LocationIntener<LOC, ID> |
74 | where | 83 | where |
75 | ID: ArenaId + Clone, | 84 | ID: ArenaId + Clone, |
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 0fae7de82..7a0301648 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use std::sync::Arc; | 1 | use std::{sync::Arc, panic}; |
2 | 2 | ||
3 | use parking_lot::Mutex; | 3 | use parking_lot::Mutex; |
4 | use salsa::{self, Database}; | 4 | use salsa::{self, Database}; |
@@ -18,6 +18,8 @@ pub(crate) struct MockDatabase { | |||
18 | file_counter: u32, | 18 | file_counter: u32, |
19 | } | 19 | } |
20 | 20 | ||
21 | impl panic::RefUnwindSafe for MockDatabase {} | ||
22 | |||
21 | impl MockDatabase { | 23 | impl MockDatabase { |
22 | pub(crate) fn with_files(fixture: &str) -> (MockDatabase, SourceRoot) { | 24 | pub(crate) fn with_files(fixture: &str) -> (MockDatabase, SourceRoot) { |
23 | let (db, source_root, position) = MockDatabase::from_fixture(fixture); | 25 | let (db, source_root, position) = MockDatabase::from_fixture(fixture); |