From 95805ee6275b4fe12cdb8845e699e7a6aa6b26eb Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Wed, 26 Oct 2016 20:16:58 -0700 Subject: [PATCH] save a borrow by using return value of HashSet::insert Thanks to Niko Matsakis's review for the suggestion. --- src/librustc/session/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 7917964c8f1..f4029fde471 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -297,18 +297,16 @@ pub fn diagnostic<'a>(&'a self) -> &'a errors::Handler { /// deduplicates on span and message for this `Session`. // // FIXME: if the need arises for one-time diagnostics other than - // `span_note`, we almost certainly want to generalize this "check the - // one-time diagnostics map, then set message if it's not already there" - // code to accomodate all of them + // `span_note`, we almost certainly want to generalize this + // "check/insert-into the one-time diagnostics map, then set message if + // it's not already there" code to accomodate all of them pub fn diag_span_note_once<'a, 'b>(&'a self, diag_builder: &'b mut DiagnosticBuilder<'a>, span: Span, message: &str) { let span_message = (span, message.to_owned()); - let already_noted: bool = self.one_time_diagnostics.borrow() - .contains(&span_message); - if !already_noted { + let fresh = self.one_time_diagnostics.borrow_mut().insert(span_message); + if fresh { diag_builder.span_note(span, &message); - self.one_time_diagnostics.borrow_mut().insert(span_message); } } -- 2.44.0