Skip to content

Commit 95805ee

Browse files
committed
save a borrow by using return value of HashSet::insert
Thanks to Niko Matsakis's review for the suggestion.
1 parent 1bfa1d5 commit 95805ee

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/librustc/session/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,16 @@ impl Session {
297297
/// deduplicates on span and message for this `Session`.
298298
//
299299
// FIXME: if the need arises for one-time diagnostics other than
300-
// `span_note`, we almost certainly want to generalize this "check the
301-
// one-time diagnostics map, then set message if it's not already there"
302-
// code to accomodate all of them
300+
// `span_note`, we almost certainly want to generalize this
301+
// "check/insert-into the one-time diagnostics map, then set message if
302+
// it's not already there" code to accomodate all of them
303303
pub fn diag_span_note_once<'a, 'b>(&'a self,
304304
diag_builder: &'b mut DiagnosticBuilder<'a>,
305305
span: Span, message: &str) {
306306
let span_message = (span, message.to_owned());
307-
let already_noted: bool = self.one_time_diagnostics.borrow()
308-
.contains(&span_message);
309-
if !already_noted {
307+
let fresh = self.one_time_diagnostics.borrow_mut().insert(span_message);
308+
if fresh {
310309
diag_builder.span_note(span, &message);
311-
self.one_time_diagnostics.borrow_mut().insert(span_message);
312310
}
313311
}
314312

0 commit comments

Comments
 (0)