Skip to content

Commit aec806e

Browse files
committed
Add unwrap method for QueryResult
It was what was already being done but with worse diagnostics
1 parent 3562c53 commit aec806e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ enum QueryResult {
4444
Poisoned,
4545
}
4646

47+
impl QueryResult {
48+
49+
/// Unwraps the query job and if poisoned will raise a [`FatalError`]
50+
fn unwrap(self) -> QueryJob {
51+
match self {
52+
Self::Started(job) => job,
53+
Self::Poisoned => FatalError.raise(),
54+
}
55+
}
56+
57+
}
58+
4759
impl<K> QueryState<K>
4860
where
4961
K: Eq + Hash + Copy + Debug,
@@ -169,10 +181,7 @@ where
169181

170182
let job = {
171183
let mut lock = state.active.lock_shard_by_value(&key);
172-
match lock.remove(&key).unwrap() {
173-
QueryResult::Started(job) => job,
174-
QueryResult::Poisoned => panic!(),
175-
}
184+
lock.remove(&key).unwrap().unwrap()
176185
};
177186

178187
job.signal_complete();
@@ -190,10 +199,8 @@ where
190199
let state = self.state;
191200
let job = {
192201
let mut shard = state.active.lock_shard_by_value(&self.key);
193-
let job = match shard.remove(&self.key).unwrap() {
194-
QueryResult::Started(job) => job,
195-
QueryResult::Poisoned => panic!(),
196-
};
202+
let job = shard.remove(&self.key).unwrap().unwrap();
203+
197204
shard.insert(self.key, QueryResult::Poisoned);
198205
job
199206
};

0 commit comments

Comments
 (0)