@@ -559,6 +559,23 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
559
559
trait_ref. to_predicate( ) ,
560
560
post_message) ;
561
561
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
+
562
579
// Try to report a help message
563
580
if !trait_ref. has_infer_types ( ) &&
564
581
self . predicate_can_apply ( trait_ref) {
@@ -571,21 +588,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
571
588
// which is somewhat confusing.
572
589
err. help ( & format ! ( "consider adding a `where {}` bound" ,
573
590
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 ( ) {
579
592
// Can't show anything else useful, try to find similar impls.
580
593
let impl_candidates = self . find_similar_impl_candidates ( trait_ref) ;
581
594
self . report_similar_impl_candidates ( impl_candidates, & mut err) ;
582
595
}
583
596
584
- err. span_label ( span,
585
- format ! ( "{}the trait `{}` is not implemented for `{}`" ,
586
- pre_message,
587
- trait_ref,
588
- trait_ref. self_ty( ) ) ) ;
589
597
err
590
598
}
591
599
0 commit comments