Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 59e49ca

Browse files
committedNov 23, 2024
rustc_interface: use refcell_try_map
1 parent 81275ce commit 59e49ca

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed
 

‎compiler/rustc_interface/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(file_buffered)]
44
#![feature(iter_intersperse)]
55
#![feature(let_chains)]
6+
#![feature(refcell_try_map)]
67
#![feature(try_blocks)]
78
#![warn(unreachable_pub)]
89
// tidy-alphabetical-end

‎compiler/rustc_interface/src/queries.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ pub struct Query<T> {
3333

3434
impl<T> Query<T> {
3535
fn compute<F: FnOnce() -> Result<T>>(&self, f: F) -> Result<QueryResult<'_, T>> {
36-
RefMut::filter_map(
37-
self.result.borrow_mut(),
38-
|r: &mut Option<Result<Steal<T>>>| -> Option<&mut Steal<T>> {
39-
r.get_or_insert_with(|| f().map(Steal::new)).as_mut().ok()
40-
},
41-
)
42-
.map_err(|r| *r.as_ref().unwrap().as_ref().map(|_| ()).unwrap_err())
43-
.map(QueryResult)
36+
let result = RefMut::try_map(self.result.borrow_mut(), |option| {
37+
match option.get_or_insert_with(|| f().map(Steal::new)) {
38+
Ok(steal) => Ok(steal),
39+
&mut Err(error) => Err(error),
40+
}
41+
});
42+
match result {
43+
Ok(r) => Ok(QueryResult(r)),
44+
Err((_, e)) => Err(e),
45+
}
4446
}
4547
}
4648

0 commit comments

Comments
 (0)
Failed to load comments.