@@ -221,7 +221,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
221
221
let mode = no_match_data. mode ;
222
222
let tcx = self . tcx ;
223
223
let rcvr_ty = self . resolve_vars_if_possible ( rcvr_ty) ;
224
- let ty_str = self . ty_to_string ( rcvr_ty) ;
224
+ let ty_str = with_forced_trimmed_paths ! ( self . ty_to_string( rcvr_ty) ) ;
225
225
let is_method = mode == Mode :: MethodCall ;
226
226
let unsatisfied_predicates = & no_match_data. unsatisfied_predicates ;
227
227
let lev_candidate = no_match_data. lev_candidate ;
@@ -523,7 +523,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
523
523
let term = pred. skip_binder ( ) . term ;
524
524
525
525
let obligation = format ! ( "{} = {}" , projection_ty, term) ;
526
- let quiet = format ! ( "{} = {}" , quiet_projection_ty, term) ;
526
+ let quiet = with_forced_trimmed_paths ! ( format!(
527
+ "{} = {}" ,
528
+ quiet_projection_ty, term
529
+ ) ) ;
527
530
528
531
bound_span_label ( projection_ty. self_ty ( ) , & obligation, & quiet) ;
529
532
Some ( ( obligation, projection_ty. self_ty ( ) ) )
@@ -533,7 +536,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
533
536
let self_ty = p. self_ty ( ) ;
534
537
let path = p. print_only_trait_path ( ) ;
535
538
let obligation = format ! ( "{}: {}" , self_ty, path) ;
536
- let quiet = format ! ( "_: {}" , path) ;
539
+ let quiet = with_forced_trimmed_paths ! ( format!( "_: {}" , path) ) ;
537
540
bound_span_label ( self_ty, & obligation, & quiet) ;
538
541
Some ( ( obligation, self_ty) )
539
542
}
@@ -636,6 +639,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
636
639
let entry = spanned_predicates. entry ( spans) ;
637
640
entry. or_insert_with ( || ( path, tr_self_ty, Vec :: new ( ) ) ) . 2 . push ( p) ;
638
641
}
642
+ Some ( Node :: Item ( hir:: Item {
643
+ kind : hir:: ItemKind :: Trait ( rustc_ast:: ast:: IsAuto :: Yes , ..) ,
644
+ span : item_span,
645
+ ..
646
+ } ) ) => {
647
+ tcx. sess . delay_span_bug (
648
+ * item_span,
649
+ "auto trait is invoked with no method error, but no error reported?" ,
650
+ ) ;
651
+ }
639
652
Some ( _) => unreachable ! ( ) ,
640
653
None => ( ) ,
641
654
}
@@ -731,9 +744,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
731
744
} else {
732
745
( None , None )
733
746
} ;
734
- let primary_message = primary_message. unwrap_or_else ( || format ! (
735
- "the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, but its trait bounds were not satisfied"
736
- ) ) ;
747
+ let primary_message = primary_message. unwrap_or_else ( || {
748
+ format ! (
749
+ "the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, \
750
+ but its trait bounds were not satisfied"
751
+ )
752
+ } ) ;
737
753
err. set_primary_message ( & primary_message) ;
738
754
if let Some ( label) = label {
739
755
custom_span_label = true ;
@@ -826,11 +842,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
826
842
}
827
843
}
828
844
} else {
845
+ let ty_str =
846
+ if ty_str. len ( ) > 50 { String :: new ( ) } else { format ! ( "on `{ty_str}` " ) } ;
829
847
err. span_label (
830
848
span,
831
- format ! (
832
- "{item_kind} cannot be called on `{ty_str}` due to unsatisfied trait bounds"
833
- ) ,
849
+ format ! ( "{item_kind} cannot be called {ty_str}due to unsatisfied trait bounds" ) ,
834
850
) ;
835
851
}
836
852
} ;
@@ -922,7 +938,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
922
938
if def_kind == DefKind :: AssocFn && lev_candidate. fn_has_self_parameter {
923
939
err. span_suggestion (
924
940
span,
925
- & format ! ( "there is a method with a similar name" , ) ,
941
+ "there is a method with a similar name" ,
926
942
lev_candidate. name ,
927
943
Applicability :: MaybeIncorrect ,
928
944
) ;
@@ -966,11 +982,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
966
982
// Provide the best span we can. Use the item, if local to crate, else
967
983
// the impl, if local to crate (item may be defaulted), else nothing.
968
984
let Some ( item) = self . associated_value ( impl_did, item_name) . or_else ( || {
969
- let impl_trait_ref = self . tcx . impl_trait_ref ( impl_did) ?;
970
- self . associated_value ( impl_trait_ref. def_id , item_name)
971
- } ) else {
972
- continue ;
973
- } ;
985
+ let impl_trait_ref = self . tcx . impl_trait_ref ( impl_did) ?;
986
+ self . associated_value ( impl_trait_ref. def_id , item_name)
987
+ } ) else {
988
+ continue ;
989
+ } ;
974
990
975
991
let note_span = if item. def_id . is_local ( ) {
976
992
Some ( self . tcx . def_span ( item. def_id ) )
@@ -1015,35 +1031,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1015
1031
err. note ( & note_str) ;
1016
1032
}
1017
1033
if let Some ( sugg_span) = sugg_span
1018
- && let Some ( trait_ref) = self . tcx . impl_trait_ref ( impl_did) {
1019
- let path = self . tcx . def_path_str ( trait_ref. def_id ) ;
1020
-
1021
- let ty = match item. kind {
1022
- ty:: AssocKind :: Const | ty:: AssocKind :: Type => rcvr_ty,
1023
- ty:: AssocKind :: Fn => self
1024
- . tcx
1025
- . fn_sig ( item. def_id )
1026
- . inputs ( )
1027
- . skip_binder ( )
1028
- . get ( 0 )
1029
- . filter ( |ty| ty. is_region_ptr ( ) && !rcvr_ty. is_region_ptr ( ) )
1030
- . copied ( )
1031
- . unwrap_or ( rcvr_ty) ,
1032
- } ;
1033
- print_disambiguation_help (
1034
- item_name,
1035
- args,
1036
- err,
1037
- path,
1038
- ty,
1039
- item. kind ,
1040
- item. def_id ,
1041
- sugg_span,
1042
- idx,
1043
- self . tcx . sess . source_map ( ) ,
1044
- item. fn_has_self_parameter ,
1045
- ) ;
1046
- }
1034
+ && let Some ( trait_ref) = self . tcx . impl_trait_ref ( impl_did) {
1035
+ let path = self . tcx . def_path_str ( trait_ref. def_id ) ;
1036
+
1037
+ let ty = match item. kind {
1038
+ ty:: AssocKind :: Const | ty:: AssocKind :: Type => rcvr_ty,
1039
+ ty:: AssocKind :: Fn => self
1040
+ . tcx
1041
+ . fn_sig ( item. def_id )
1042
+ . inputs ( )
1043
+ . skip_binder ( )
1044
+ . get ( 0 )
1045
+ . filter ( |ty| ty. is_region_ptr ( ) && !rcvr_ty. is_region_ptr ( ) )
1046
+ . copied ( )
1047
+ . unwrap_or ( rcvr_ty) ,
1048
+ } ;
1049
+ print_disambiguation_help (
1050
+ item_name,
1051
+ args,
1052
+ err,
1053
+ path,
1054
+ ty,
1055
+ item. kind ,
1056
+ item. def_id ,
1057
+ sugg_span,
1058
+ idx,
1059
+ self . tcx . sess . source_map ( ) ,
1060
+ item. fn_has_self_parameter ,
1061
+ ) ;
1062
+ }
1047
1063
}
1048
1064
CandidateSource :: Trait ( trait_did) => {
1049
1065
let Some ( item) = self . associated_value ( trait_did, item_name) else { continue } ;
0 commit comments