Skip to content

Commit 0c58839

Browse files
committed
internal: remove Default from OpQueue
1 parent af9a658 commit 0c58839

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ 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+
|| self.fetch_proc_macros_queue.last_op_result().copied().unwrap_or(false),
506506
flycheck: self.flycheck.clone(),
507507
}
508508
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,11 @@ impl GlobalState {
549549
let subscriptions = subscriptions.clone();
550550
// Do not fetch semantic diagnostics (and populate query results) if we haven't even
551551
// loaded the initial workspace yet.
552-
let fetch_semantic =
553-
self.vfs_done && self.fetch_workspaces_queue.last_op_result().is_some();
552+
let fetch_semantic = self.vfs_done
553+
&& self
554+
.fetch_workspaces_queue
555+
.last_op_result()
556+
.is_some_and(|inner| inner.is_some());
554557
move |sender| {
555558
// We aren't observing the semantics token cache here
556559
let snapshot = AssertUnwindSafe(&snapshot);

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: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl GlobalState {
448448
let _p = tracing::info_span!("GlobalState::switch_workspaces").entered();
449449
tracing::info!(%cause, "will switch workspaces");
450450

451-
let Some((workspaces, force_reload_crate_graph)) =
451+
let Some(Some((workspaces, force_reload_crate_graph))) =
452452
self.fetch_workspaces_queue.last_op_result()
453453
else {
454454
return;
@@ -474,8 +474,12 @@ 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();
478-
if Arc::ptr_eq(workspaces, &self.workspaces) {
477+
let (workspaces, build_scripts) = match self.fetch_build_data_queue.last_op_result() {
478+
Some((workspaces, build_scripts)) => (workspaces.clone(), build_scripts.as_slice()),
479+
None => (Default::default(), Default::default()),
480+
};
481+
482+
if Arc::ptr_eq(&workspaces, &self.workspaces) {
479483
info!("set build scripts to workspaces");
480484

481485
let workspaces = workspaces
@@ -739,7 +743,7 @@ impl GlobalState {
739743
pub(super) fn fetch_workspace_error(&self) -> Result<(), String> {
740744
let mut buf = String::new();
741745

742-
let Some((last_op_result, _)) = self.fetch_workspaces_queue.last_op_result() else {
746+
let Some(Some((last_op_result, _))) = self.fetch_workspaces_queue.last_op_result() else {
743747
return Ok(());
744748
};
745749

@@ -769,7 +773,11 @@ impl GlobalState {
769773
pub(super) fn fetch_build_data_error(&self) -> Result<(), String> {
770774
let mut buf = String::new();
771775

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

0 commit comments

Comments
 (0)