Skip to content

Commit 29c9834

Browse files
committed
internal: remove Default from OpQueue
1 parent af9a658 commit 29c9834

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub(crate) struct GlobalState {
147147

148148
// op queues
149149
pub(crate) fetch_workspaces_queue:
150-
OpQueue<FetchWorkspaceRequest, Option<(Vec<anyhow::Result<ProjectWorkspace>>, bool)>>,
150+
OpQueue<FetchWorkspaceRequest, (Vec<anyhow::Result<ProjectWorkspace>>, bool)>,
151151
pub(crate) fetch_build_data_queue:
152152
OpQueue<(), (Arc<Vec<ProjectWorkspace>>, Vec<anyhow::Result<WorkspaceBuildScripts>>)>,
153153
pub(crate) fetch_proc_macros_queue: OpQueue<Vec<ProcMacroPaths>, bool>,
@@ -502,7 +502,11 @@ impl GlobalState {
502502
mem_docs: self.mem_docs.clone(),
503503
semantic_tokens_cache: Arc::clone(&self.semantic_tokens_cache),
504504
proc_macros_loaded: !self.config.expand_proc_macros()
505-
|| *self.fetch_proc_macros_queue.last_op_result(),
505+
|| if let Some(loaded) = self.fetch_proc_macros_queue.last_op_result() {
506+
*loaded
507+
} else {
508+
false
509+
},
506510
flycheck: self.flycheck.clone(),
507511
}
508512
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ impl GlobalState {
697697
ProjectWorkspaceProgress::Report(msg) => (Progress::Report, Some(msg)),
698698
ProjectWorkspaceProgress::End(workspaces, force_reload_crate_graph) => {
699699
self.fetch_workspaces_queue
700-
.op_completed(Some((workspaces, force_reload_crate_graph)));
700+
.op_completed((workspaces, force_reload_crate_graph));
701701
if let Err(e) = self.fetch_workspace_error() {
702702
error!("FetchWorkspaceError: {e}");
703703
}

crates/rust-analyzer/src/op_queue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ pub(crate) type Cause = String;
2727
pub(crate) struct OpQueue<Args = (), Output = ()> {
2828
op_requested: Option<(Cause, Args)>,
2929
op_in_progress: bool,
30-
last_op_result: Output,
30+
last_op_result: Option<Output>,
3131
}
3232

33-
impl<Args, Output: Default> Default for OpQueue<Args, Output> {
33+
impl<Args, Output> Default for OpQueue<Args, Output> {
3434
fn default() -> Self {
35-
Self { op_requested: None, op_in_progress: false, last_op_result: Default::default() }
35+
Self { op_requested: None, op_in_progress: false, last_op_result: None }
3636
}
3737
}
3838

@@ -56,12 +56,12 @@ impl<Args, Output> OpQueue<Args, Output> {
5656
pub(crate) fn op_completed(&mut self, result: Output) {
5757
assert!(self.op_in_progress);
5858
self.op_in_progress = false;
59-
self.last_op_result = result;
59+
self.last_op_result = Some(result);
6060
}
6161

6262
/// Get the result of the last operation.
63-
pub(crate) fn last_op_result(&self) -> &Output {
64-
&self.last_op_result
63+
pub(crate) fn last_op_result(&self) -> Option<&Output> {
64+
self.last_op_result.as_ref()
6565
}
6666

6767
// Is there an operation that has started, but hasn't yet finished?

crates/rust-analyzer/src/reload.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ impl GlobalState {
474474
.all(|(l, r)| l.eq_ignore_build_data(r));
475475

476476
if same_workspaces {
477-
let (workspaces, build_scripts) = self.fetch_build_data_queue.last_op_result();
477+
let Some((workspaces, build_scripts)) = self.fetch_build_data_queue.last_op_result()
478+
else {
479+
return;
480+
};
478481
if Arc::ptr_eq(workspaces, &self.workspaces) {
479482
info!("set build scripts to workspaces");
480483

@@ -769,7 +772,11 @@ impl GlobalState {
769772
pub(super) fn fetch_build_data_error(&self) -> Result<(), String> {
770773
let mut buf = String::new();
771774

772-
for ws in &self.fetch_build_data_queue.last_op_result().1 {
775+
let Some((_, ws)) = &self.fetch_build_data_queue.last_op_result() else {
776+
return Ok(());
777+
};
778+
779+
for ws in ws {
773780
match ws {
774781
Ok(data) => {
775782
if let Some(stderr) = data.error() {

0 commit comments

Comments
 (0)