@@ -525,127 +525,126 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
525
525
lint_id)
526
526
. emit ( ) ;
527
527
return ;
528
- } else {
529
- match obligation. predicate {
530
- ty:: Predicate :: Trait ( ref trait_predicate) => {
531
- let trait_predicate =
532
- self . resolve_type_vars_if_possible ( trait_predicate) ;
528
+ }
529
+ match obligation. predicate {
530
+ ty:: Predicate :: Trait ( ref trait_predicate) => {
531
+ let trait_predicate =
532
+ self . resolve_type_vars_if_possible ( trait_predicate) ;
533
533
534
- if self . tcx . sess . has_errors ( ) && trait_predicate. references_error ( ) {
535
- return ;
534
+ if self . tcx . sess . has_errors ( ) && trait_predicate. references_error ( ) {
535
+ return ;
536
+ } else {
537
+ let trait_ref = trait_predicate. to_poly_trait_ref ( ) ;
538
+ let ( post_message, pre_message) = match self . get_parent_trait_ref (
539
+ & obligation. cause . code )
540
+ {
541
+ Some ( t) => {
542
+ ( format ! ( " in `{}`" , t) , format ! ( "within `{}`, " , t) )
543
+ }
544
+ None => ( String :: new ( ) , String :: new ( ) ) ,
545
+ } ;
546
+ let mut err = struct_span_err ! (
547
+ self . tcx. sess,
548
+ span,
549
+ E0277 ,
550
+ "the trait bound `{}` is not satisfied{}" ,
551
+ trait_ref. to_predicate( ) ,
552
+ post_message) ;
553
+ err. span_label ( span,
554
+ & format ! ( "{}the trait `{}` is not \
555
+ implemented for `{}`",
556
+ pre_message,
557
+ trait_ref,
558
+ trait_ref. self_ty( ) ) ) ;
559
+
560
+ // Try to report a help message
561
+
562
+ if !trait_ref. has_infer_types ( ) &&
563
+ self . predicate_can_apply ( trait_ref) {
564
+ // If a where-clause may be useful, remind the
565
+ // user that they can add it.
566
+ //
567
+ // don't display an on-unimplemented note, as
568
+ // these notes will often be of the form
569
+ // "the type `T` can't be frobnicated"
570
+ // which is somewhat confusing.
571
+ err. help ( & format ! ( "consider adding a `where {}` bound" ,
572
+ trait_ref. to_predicate( ) ) ) ;
573
+ } else if let Some ( s) = self . on_unimplemented_note ( trait_ref,
574
+ obligation) {
575
+ // If it has a custom "#[rustc_on_unimplemented]"
576
+ // error message, let's display it!
577
+ err. note ( & s) ;
536
578
} else {
537
- let trait_ref = trait_predicate. to_poly_trait_ref ( ) ;
538
- let ( post_message, pre_message) = match self . get_parent_trait_ref (
539
- & obligation. cause . code )
540
- {
541
- Some ( t) => {
542
- ( format ! ( " in `{}`" , t) , format ! ( "within `{}`, " , t) )
543
- }
544
- None => ( String :: new ( ) , String :: new ( ) ) ,
545
- } ;
546
- let mut err = struct_span_err ! (
547
- self . tcx. sess,
548
- span,
549
- E0277 ,
550
- "the trait bound `{}` is not satisfied{}" ,
551
- trait_ref. to_predicate( ) ,
552
- post_message) ;
553
- err. span_label ( span,
554
- & format ! ( "{}the trait `{}` is not \
555
- implemented for `{}`",
556
- pre_message,
557
- trait_ref,
558
- trait_ref. self_ty( ) ) ) ;
559
-
560
- // Try to report a help message
561
-
562
- if !trait_ref. has_infer_types ( ) &&
563
- self . predicate_can_apply ( trait_ref) {
564
- // If a where-clause may be useful, remind the
565
- // user that they can add it.
566
- //
567
- // don't display an on-unimplemented note, as
568
- // these notes will often be of the form
569
- // "the type `T` can't be frobnicated"
570
- // which is somewhat confusing.
571
- err. help ( & format ! ( "consider adding a `where {}` bound" ,
572
- trait_ref. to_predicate( ) ) ) ;
573
- } else if let Some ( s) = self . on_unimplemented_note ( trait_ref,
574
- obligation) {
575
- // If it has a custom "#[rustc_on_unimplemented]"
576
- // error message, let's display it!
577
- err. note ( & s) ;
578
- } else {
579
- // If we can't show anything useful, try to find
580
- // similar impls.
581
- let impl_candidates =
582
- self . find_similar_impl_candidates ( trait_ref) ;
583
- if impl_candidates. len ( ) > 0 {
584
- self . report_similar_impl_candidates ( trait_ref, & mut err) ;
585
- }
579
+ // If we can't show anything useful, try to find
580
+ // similar impls.
581
+ let impl_candidates =
582
+ self . find_similar_impl_candidates ( trait_ref) ;
583
+ if impl_candidates. len ( ) > 0 {
584
+ self . report_similar_impl_candidates ( trait_ref, & mut err) ;
586
585
}
587
- err
588
586
}
587
+ err
589
588
}
589
+ }
590
590
591
- ty:: Predicate :: Equate ( ref predicate) => {
592
- let predicate = self . resolve_type_vars_if_possible ( predicate) ;
593
- let err = self . equality_predicate ( & obligation. cause ,
594
- & predicate) . err ( ) . unwrap ( ) ;
595
- struct_span_err ! ( self . tcx. sess, span, E0278 ,
596
- "the requirement `{}` is not satisfied (`{}`)" ,
597
- predicate, err)
598
- }
591
+ ty:: Predicate :: Equate ( ref predicate) => {
592
+ let predicate = self . resolve_type_vars_if_possible ( predicate) ;
593
+ let err = self . equality_predicate ( & obligation. cause ,
594
+ & predicate) . err ( ) . unwrap ( ) ;
595
+ struct_span_err ! ( self . tcx. sess, span, E0278 ,
596
+ "the requirement `{}` is not satisfied (`{}`)" ,
597
+ predicate, err)
598
+ }
599
599
600
- ty:: Predicate :: RegionOutlives ( ref predicate) => {
601
- let predicate = self . resolve_type_vars_if_possible ( predicate) ;
602
- let err = self . region_outlives_predicate ( & obligation. cause ,
603
- & predicate) . err ( ) . unwrap ( ) ;
604
- struct_span_err ! ( self . tcx. sess, span, E0279 ,
605
- "the requirement `{}` is not satisfied (`{}`)" ,
606
- predicate, err)
607
- }
600
+ ty:: Predicate :: RegionOutlives ( ref predicate) => {
601
+ let predicate = self . resolve_type_vars_if_possible ( predicate) ;
602
+ let err = self . region_outlives_predicate ( & obligation. cause ,
603
+ & predicate) . err ( ) . unwrap ( ) ;
604
+ struct_span_err ! ( self . tcx. sess, span, E0279 ,
605
+ "the requirement `{}` is not satisfied (`{}`)" ,
606
+ predicate, err)
607
+ }
608
608
609
- ty:: Predicate :: Projection ( ..) | ty:: Predicate :: TypeOutlives ( ..) => {
610
- let predicate =
611
- self . resolve_type_vars_if_possible ( & obligation. predicate ) ;
612
- struct_span_err ! ( self . tcx. sess, span, E0280 ,
613
- "the requirement `{}` is not satisfied" ,
614
- predicate)
615
- }
609
+ ty:: Predicate :: Projection ( ..) | ty:: Predicate :: TypeOutlives ( ..) => {
610
+ let predicate =
611
+ self . resolve_type_vars_if_possible ( & obligation. predicate ) ;
612
+ struct_span_err ! ( self . tcx. sess, span, E0280 ,
613
+ "the requirement `{}` is not satisfied" ,
614
+ predicate)
615
+ }
616
616
617
- ty:: Predicate :: ObjectSafe ( trait_def_id) => {
618
- let violations = self . tcx . object_safety_violations ( trait_def_id) ;
619
- self . tcx . report_object_safety_error ( span,
620
- trait_def_id,
621
- violations)
622
- }
617
+ ty:: Predicate :: ObjectSafe ( trait_def_id) => {
618
+ let violations = self . tcx . object_safety_violations ( trait_def_id) ;
619
+ self . tcx . report_object_safety_error ( span,
620
+ trait_def_id,
621
+ violations)
622
+ }
623
623
624
- ty:: Predicate :: ClosureKind ( closure_def_id, kind) => {
625
- let found_kind = self . closure_kind ( closure_def_id) . unwrap ( ) ;
626
- let closure_span = self . tcx . hir . span_if_local ( closure_def_id) . unwrap ( ) ;
627
- let mut err = struct_span_err ! (
628
- self . tcx. sess, closure_span, E0525 ,
629
- "expected a closure that implements the `{}` trait, \
630
- but this closure only implements `{}`",
631
- kind,
632
- found_kind) ;
633
- err. span_note (
634
- obligation. cause . span ,
635
- & format ! ( "the requirement to implement \
636
- `{}` derives from here", kind) ) ;
637
- err. emit ( ) ;
638
- return ;
639
- }
624
+ ty:: Predicate :: ClosureKind ( closure_def_id, kind) => {
625
+ let found_kind = self . closure_kind ( closure_def_id) . unwrap ( ) ;
626
+ let closure_span = self . tcx . hir . span_if_local ( closure_def_id) . unwrap ( ) ;
627
+ let mut err = struct_span_err ! (
628
+ self . tcx. sess, closure_span, E0525 ,
629
+ "expected a closure that implements the `{}` trait, \
630
+ but this closure only implements `{}`",
631
+ kind,
632
+ found_kind) ;
633
+ err. span_note (
634
+ obligation. cause . span ,
635
+ & format ! ( "the requirement to implement \
636
+ `{}` derives from here", kind) ) ;
637
+ err. emit ( ) ;
638
+ return ;
639
+ }
640
640
641
- ty:: Predicate :: WellFormed ( ty) => {
642
- // WF predicates cannot themselves make
643
- // errors. They can only block due to
644
- // ambiguity; otherwise, they always
645
- // degenerate into other obligations
646
- // (which may fail).
647
- span_bug ! ( span, "WF predicate not satisfied for {:?}" , ty) ;
648
- }
641
+ ty:: Predicate :: WellFormed ( ty) => {
642
+ // WF predicates cannot themselves make
643
+ // errors. They can only block due to
644
+ // ambiguity; otherwise, they always
645
+ // degenerate into other obligations
646
+ // (which may fail).
647
+ span_bug ! ( span, "WF predicate not satisfied for {:?}" , ty) ;
649
648
}
650
649
}
651
650
}
0 commit comments