diff --git a/compiler/rustc_query_impl/src/job.rs b/compiler/rustc_query_impl/src/job.rs
index 19b8245b97e7a..7fa5882bc8e95 100644
--- a/compiler/rustc_query_impl/src/job.rs
+++ b/compiler/rustc_query_impl/src/job.rs
@@ -1,5 +1,6 @@
use std::io::Write;
use std::iter;
+use std::ops::ControlFlow;
use std::sync::Arc;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -117,41 +118,33 @@ type Waiter = (QueryJobId, usize);
/// Visits all the non-resumable and resumable waiters of a query.
/// Only waiters in a query are visited.
-/// `visit` is called for every waiter and is passed a query waiting on `query_ref`
-/// and a span indicating the reason the query waited on `query_ref`.
-/// If `visit` returns Some, this function returns.
+/// `visit` is called for every waiter and is passed a query waiting on `query`
+/// and a span indicating the reason the query waited on `query`.
+/// If `visit` returns `Break`, this function also returns `Break`,
+/// and if all `visit` calls returns `Continue` it also returns `Continue`.
/// For visits of non-resumable waiters it returns the return value of `visit`.
-/// For visits of resumable waiters it returns Some(Some(Waiter)) which has the
-/// required information to resume the waiter.
-/// If all `visit` calls returns None, this function also returns None.
-fn visit_waiters<'tcx, F>(
+/// For visits of resumable waiters it returns information required to resume that waiter.
+fn visit_waiters<'tcx>(
job_map: &QueryJobMap<'tcx>,
query: QueryJobId,
- mut visit: F,
-) -> Option