Skip to content

Commit

Permalink
save a borrow by using return value of HashSet::insert
Browse files Browse the repository at this point in the history
Thanks to Niko Matsakis's review for the suggestion.
  • Loading branch information
zackmdavis committed Oct 27, 2016
1 parent 1bfa1d5 commit 95805ee
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,16 @@ impl Session {
/// 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);
}
}

Expand Down

0 comments on commit 95805ee

Please sign in to comment.