Skip to content

Commit 28848d7

Browse files
committed
Tweak control flow in query_* functions.
`query_get_at`, `query_ensure`, and `query_ensure_error_guarantee` are very similar functions, but they all use different control flow styles which obscures the similarities. This commit rewrites them to all use a `match`.
1 parent d2218f5 commit 28848d7

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

compiler/rustc_middle/src/query/inner.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ pub(crate) fn query_ensure<'tcx, C>(
5959
) where
6060
C: QueryCache,
6161
{
62-
if try_get_cached(tcx, &query.cache, &key).is_none() {
63-
(query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure { ensure_mode });
62+
match try_get_cached(tcx, &query.cache, &key) {
63+
Some(_value) => {}
64+
None => {
65+
(query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure { ensure_mode });
66+
}
6467
}
6568
}
6669

@@ -81,19 +84,18 @@ where
8184
{
8285
assert_matches!(ensure_mode, EnsureMode::Ok);
8386

84-
if let Some(res) = try_get_cached(tcx, &query.cache, &key) {
85-
erase::restore_val(res).map(drop)
86-
} else {
87-
(query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure { ensure_mode })
87+
match try_get_cached(tcx, &query.cache, &key) {
88+
Some(value) => erase::restore_val(value).map(drop),
89+
None => (query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure { ensure_mode })
8890
.map(erase::restore_val)
89-
.map(|res| res.map(drop))
91+
.map(|value| value.map(drop))
9092
// Either we actually executed the query, which means we got a full `Result`,
9193
// or we can just assume the query succeeded, because it was green in the
9294
// incremental cache. If it is green, that means that the previous compilation
9395
// that wrote to the incremental cache compiles successfully. That is only
9496
// possible if the cache entry was `Ok(())`, so we emit that here, without
9597
// actually encoding the `Result` in the cache or loading it from there.
96-
.unwrap_or(Ok(()))
98+
.unwrap_or(Ok(())),
9799
}
98100
}
99101

0 commit comments

Comments
 (0)