@@ -412,8 +412,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
412
412
let bound_predicate = obligation. predicate . kind ( ) ;
413
413
match bound_predicate. skip_binder ( ) {
414
414
ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Trait ( trait_predicate) ) => {
415
- let trait_predicate = bound_predicate . rebind ( trait_predicate ) ;
416
- let trait_predicate = self . resolve_vars_if_possible ( trait_predicate) ;
415
+ let trait_predicate =
416
+ self . resolve_vars_if_possible ( bound_predicate . rebind ( trait_predicate) ) ;
417
417
418
418
// Let's use the root obligation as the main message, when we care about the
419
419
// most general case ("X doesn't implement Pattern<'_>") over the case that
@@ -461,11 +461,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
461
461
} else {
462
462
( trait_predicate, & obligation)
463
463
} ;
464
- let trait_ref = main_trait_predicate. to_poly_trait_ref ( ) ;
464
+ let main_trait_ref = main_trait_predicate. to_poly_trait_ref ( ) ;
465
465
466
466
if let Some ( guar) = self . emit_specialized_closure_kind_error (
467
467
& obligation,
468
- trait_ref ,
468
+ main_trait_ref ,
469
469
) {
470
470
return guar;
471
471
}
@@ -507,16 +507,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
507
507
notes,
508
508
parent_label,
509
509
append_const_msg,
510
- } = self . on_unimplemented_note ( trait_ref , o, & mut long_ty_file) ;
510
+ } = self . on_unimplemented_note ( main_trait_ref , o, & mut long_ty_file) ;
511
511
let have_alt_message = message. is_some ( ) || label. is_some ( ) ;
512
- let is_try_conversion = self . is_try_conversion ( span, trait_ref . def_id ( ) ) ;
512
+ let is_try_conversion = self . is_try_conversion ( span, main_trait_ref . def_id ( ) ) ;
513
513
let is_unsize =
514
- Some ( trait_ref . def_id ( ) ) == self . tcx . lang_items ( ) . unsize_trait ( ) ;
514
+ Some ( main_trait_ref . def_id ( ) ) == self . tcx . lang_items ( ) . unsize_trait ( ) ;
515
515
let ( message, notes, append_const_msg) = if is_try_conversion {
516
516
(
517
517
Some ( format ! (
518
518
"`?` couldn't convert the error to `{}`" ,
519
- trait_ref . skip_binder( ) . self_ty( ) ,
519
+ main_trait_ref . skip_binder( ) . self_ty( ) ,
520
520
) ) ,
521
521
vec ! [
522
522
"the question mark operation (`?`) implicitly performs a \
@@ -537,13 +537,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
537
537
post_message,
538
538
) ;
539
539
540
- let ( err_msg, safe_transmute_explanation) = if Some ( trait_ref . def_id ( ) )
540
+ let ( err_msg, safe_transmute_explanation) = if Some ( main_trait_ref . def_id ( ) )
541
541
== self . tcx . lang_items ( ) . transmute_trait ( )
542
542
{
543
543
// Recompute the safe transmute reason and use that for the error reporting
544
544
match self . get_safe_transmute_error_and_reason (
545
545
obligation. clone ( ) ,
546
- trait_ref ,
546
+ main_trait_ref ,
547
547
span,
548
548
) {
549
549
GetSafeTransmuteErrorAndReason :: Silent => {
@@ -571,27 +571,27 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
571
571
}
572
572
let mut suggested = false ;
573
573
if is_try_conversion {
574
- suggested = self . try_conversion_context ( & obligation, trait_ref . skip_binder ( ) , & mut err) ;
574
+ suggested = self . try_conversion_context ( & obligation, main_trait_ref . skip_binder ( ) , & mut err) ;
575
575
}
576
576
577
577
if is_try_conversion && let Some ( ret_span) = self . return_type_span ( & obligation) {
578
578
err. span_label (
579
579
ret_span,
580
580
format ! (
581
581
"expected `{}` because of this" ,
582
- trait_ref . skip_binder( ) . self_ty( )
582
+ main_trait_ref . skip_binder( ) . self_ty( )
583
583
) ,
584
584
) ;
585
585
}
586
586
587
- if Some ( trait_ref . def_id ( ) ) == tcx. lang_items ( ) . tuple_trait ( ) {
587
+ if Some ( main_trait_ref . def_id ( ) ) == tcx. lang_items ( ) . tuple_trait ( ) {
588
588
self . add_tuple_trait_message (
589
589
obligation. cause . code ( ) . peel_derives ( ) ,
590
590
& mut err,
591
591
) ;
592
592
}
593
593
594
- if Some ( trait_ref . def_id ( ) ) == tcx. lang_items ( ) . drop_trait ( )
594
+ if Some ( main_trait_ref . def_id ( ) ) == tcx. lang_items ( ) . drop_trait ( )
595
595
&& predicate_is_const
596
596
{
597
597
err. note ( "`~const Drop` was renamed to `~const Destruct`" ) ;
@@ -601,8 +601,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
601
601
let explanation = get_explanation_based_on_obligation (
602
602
self . tcx ,
603
603
& obligation,
604
- trait_ref ,
605
- & trait_predicate ,
604
+ main_trait_ref ,
605
+ & main_trait_predicate ,
606
606
pre_message,
607
607
) ;
608
608
@@ -626,7 +626,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
626
626
// If it has a custom `#[rustc_on_unimplemented]`
627
627
// error message, let's display it as the label!
628
628
err. span_label ( span, s) ;
629
- if !matches ! ( trait_ref . skip_binder( ) . self_ty( ) . kind( ) , ty:: Param ( _) ) {
629
+ if !matches ! ( main_trait_ref . skip_binder( ) . self_ty( ) . kind( ) , ty:: Param ( _) ) {
630
630
// When the self type is a type param We don't need to "the trait
631
631
// `std::marker::Sized` is not implemented for `T`" as we will point
632
632
// at the type param with a label to suggest constraining it.
@@ -641,7 +641,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
641
641
if let ObligationCauseCode :: Coercion { source, target } =
642
642
* obligation. cause . code ( ) . peel_derives ( )
643
643
{
644
- if Some ( trait_ref . def_id ( ) ) == self . tcx . lang_items ( ) . sized_trait ( ) {
644
+ if Some ( main_trait_ref . def_id ( ) ) == self . tcx . lang_items ( ) . sized_trait ( ) {
645
645
self . suggest_borrowing_for_object_cast (
646
646
& mut err,
647
647
root_obligation,
@@ -670,15 +670,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
670
670
err. span_label ( tcx. def_span ( body) , s) ;
671
671
}
672
672
673
- self . suggest_floating_point_literal ( & obligation, & mut err, & trait_ref ) ;
673
+ self . suggest_floating_point_literal ( & obligation, & mut err, & main_trait_ref ) ;
674
674
self . suggest_dereferencing_index ( & obligation, & mut err, trait_predicate) ;
675
675
suggested |= self . suggest_dereferences ( & obligation, & mut err, trait_predicate) ;
676
676
suggested |= self . suggest_fn_call ( & obligation, & mut err, trait_predicate) ;
677
677
let impl_candidates = self . find_similar_impl_candidates ( trait_predicate) ;
678
678
suggested = if let & [ cand] = & impl_candidates[ ..] {
679
679
let cand = cand. trait_ref ;
680
680
if let ( ty:: FnPtr ( _) , ty:: FnDef ( ..) ) =
681
- ( cand. self_ty ( ) . kind ( ) , trait_ref . self_ty ( ) . skip_binder ( ) . kind ( ) )
681
+ ( cand. self_ty ( ) . kind ( ) , main_trait_ref . self_ty ( ) . skip_binder ( ) . kind ( ) )
682
682
{
683
683
err. span_suggestion (
684
684
span. shrink_to_hi ( ) ,
@@ -705,11 +705,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
705
705
span,
706
706
trait_predicate,
707
707
) ;
708
- self . note_version_mismatch ( & mut err, & trait_ref ) ;
708
+ self . note_version_mismatch ( & mut err, & main_trait_ref ) ;
709
709
self . suggest_remove_await ( & obligation, & mut err) ;
710
710
self . suggest_derive ( & obligation, & mut err, trait_predicate) ;
711
711
712
- if Some ( trait_ref . def_id ( ) ) == tcx. lang_items ( ) . try_trait ( ) {
712
+ if Some ( main_trait_ref . def_id ( ) ) == tcx. lang_items ( ) . try_trait ( ) {
713
713
self . suggest_await_before_try (
714
714
& mut err,
715
715
& obligation,
@@ -737,9 +737,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
737
737
) ;
738
738
}
739
739
740
- let is_fn_trait = tcx. is_fn_trait ( trait_ref . def_id ( ) ) ;
740
+ let is_fn_trait = tcx. is_fn_trait ( main_trait_ref . def_id ( ) ) ;
741
741
let is_target_feature_fn = if let ty:: FnDef ( def_id, _) =
742
- * trait_ref . skip_binder ( ) . self_ty ( ) . kind ( )
742
+ * main_trait_ref . skip_binder ( ) . self_ty ( ) . kind ( )
743
743
{
744
744
!self . tcx . codegen_fn_attrs ( def_id) . target_features . is_empty ( )
745
745
} else {
@@ -753,8 +753,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
753
753
754
754
self . try_to_add_help_message (
755
755
& obligation,
756
- trait_ref ,
757
- & trait_predicate ,
756
+ main_trait_ref ,
757
+ & main_trait_predicate ,
758
758
& mut err,
759
759
span,
760
760
is_fn_trait,
@@ -791,7 +791,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
791
791
}
792
792
793
793
self . explain_hrtb_projection ( & mut err, trait_predicate, obligation. param_env , & obligation. cause ) ;
794
- self . suggest_desugaring_async_fn_in_trait ( & mut err, trait_ref ) ;
794
+ self . suggest_desugaring_async_fn_in_trait ( & mut err, main_trait_ref ) ;
795
795
796
796
// Return early if the trait is Debug or Display and the invocation
797
797
// originates within a standard library macro, because the output
@@ -809,15 +809,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
809
809
810
810
if in_std_macro
811
811
&& matches ! (
812
- self . tcx. get_diagnostic_name( trait_ref . def_id( ) ) ,
812
+ self . tcx. get_diagnostic_name( main_trait_ref . def_id( ) ) ,
813
813
Some ( sym:: Debug | sym:: Display )
814
814
)
815
815
{
816
816
return err. emit ( ) ;
817
817
}
818
818
819
-
820
-
821
819
err
822
820
}
823
821
0 commit comments