@@ -559,6 +559,23 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
559559 trait_ref. to_predicate( ) ,
560560 post_message) ;
561561
562+ let unimplemented_note = self . on_unimplemented_note ( trait_ref, obligation) ;
563+ if let Some ( ref s) = unimplemented_note {
564+ // If it has a custom "#[rustc_on_unimplemented]"
565+ // error message, let's display it as the label!
566+ err. span_label ( span, s. as_str ( ) ) ;
567+ err. help ( & format ! ( "{}the trait `{}` is not implemented for `{}`" ,
568+ pre_message,
569+ trait_ref,
570+ trait_ref. self_ty( ) ) ) ;
571+ } else {
572+ err. span_label ( span,
573+ & * format ! ( "{}the trait `{}` is not implemented for `{}`" ,
574+ pre_message,
575+ trait_ref,
576+ trait_ref. self_ty( ) ) ) ;
577+ }
578+
562579 // Try to report a help message
563580 if !trait_ref. has_infer_types ( ) &&
564581 self . predicate_can_apply ( trait_ref) {
@@ -571,21 +588,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
571588 // which is somewhat confusing.
572589 err. help ( & format ! ( "consider adding a `where {}` bound" ,
573590 trait_ref. to_predicate( ) ) ) ;
574- } else if let Some ( s) = self . on_unimplemented_note ( trait_ref, obligation) {
575- // If it has a custom "#[rustc_on_unimplemented]"
576- // error message, let's display it!
577- err. note ( & s) ;
578- } else {
591+ } else if unimplemented_note. is_none ( ) {
579592 // Can't show anything else useful, try to find similar impls.
580593 let impl_candidates = self . find_similar_impl_candidates ( trait_ref) ;
581594 self . report_similar_impl_candidates ( impl_candidates, & mut err) ;
582595 }
583596
584- err. span_label ( span,
585- format ! ( "{}the trait `{}` is not implemented for `{}`" ,
586- pre_message,
587- trait_ref,
588- trait_ref. self_ty( ) ) ) ;
589597 err
590598 }
591599
0 commit comments