Skip to content

Commit 96a2ded

Browse files
committed
Hoist redundant-note check out of the note loop
The condition is loop-invariant, so iterating the notes only to skip every one wastes work. Test the derive suggestion once and skip the whole loop when it will be shown.
1 parent 8685d8f commit 96a2ded

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
458458
let derive_suggestion_will_be_shown = main_trait_predicate
459459
== leaf_trait_predicate
460460
&& self.can_suggest_derive(&obligation, leaf_trait_predicate);
461-
for note in notes {
462-
// If it has a custom `#[rustc_on_unimplemented]` note, let's display it
463-
if derive_suggestion_will_be_shown {
464-
continue;
461+
if !derive_suggestion_will_be_shown {
462+
for note in notes {
463+
// If it has a custom `#[rustc_on_unimplemented]` note, let's display
464+
// it.
465+
err.note(note);
465466
}
466-
err.note(note);
467467
}
468468
if let Some(s) = parent_label {
469469
let body = obligation.cause.body_id;

0 commit comments

Comments
 (0)