From 6e9573936f1ac8079c9b0b43306e82269f5be6e7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 1 Dec 2023 08:23:34 +1100 Subject: [PATCH] `Handler` tweaks. - Avoid unnecessary `inner` local variables. - Use `borrow_mut` everywhere (instead of the synonym `lock`). --- compiler/rustc_errors/src/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 85c521b0743..5966fd80f97 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -648,7 +648,7 @@ impl Handler { // This is here to not allow mutation of flags; // as of this writing it's only used in tests in librustc_middle. pub fn can_emit_warnings(&self) -> bool { - self.inner.lock().flags.can_emit_warnings + self.inner.borrow_mut().flags.can_emit_warnings } /// Resets the diagnostic error count as well as the cached emitted diagnostics. @@ -675,14 +675,13 @@ impl Handler { /// Stash a given diagnostic with the given `Span` and [`StashKey`] as the key. /// Retrieve a stashed diagnostic with `steal_diagnostic`. pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) { - let mut inner = self.inner.borrow_mut(); - inner.stash((span.with_parent(None), key), diag); + self.inner.borrow_mut().stash((span.with_parent(None), key), diag); } /// Steal a previously stashed diagnostic with the given `Span` and [`StashKey`] as the key. pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option> { - let mut inner = self.inner.borrow_mut(); - inner + self.inner + .borrow_mut() .steal((span.with_parent(None), key)) .map(|diag| DiagnosticBuilder::new_diagnostic(self, diag)) } @@ -1197,8 +1196,7 @@ impl Handler { mut diag: Diagnostic, sp: impl Into, ) -> Option { - let mut inner = self.inner.borrow_mut(); - inner.emit_diagnostic(diag.set_span(sp)) + self.inner.borrow_mut().emit_diagnostic(diag.set_span(sp)) } pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str) { @@ -1266,7 +1264,7 @@ impl Handler { } pub fn flush_delayed(&self) { - let mut inner = self.inner.lock(); + let mut inner = self.inner.borrow_mut(); let bugs = std::mem::replace(&mut inner.span_delayed_bugs, Vec::new()); inner.flush_delayed(bugs, "no errors encountered even though `span_delayed_bug` issued"); }