@@ -221,7 +221,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
221221 let mode = no_match_data. mode ;
222222 let tcx = self . tcx ;
223223 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) ) ;
225225 let is_method = mode == Mode :: MethodCall ;
226226 let unsatisfied_predicates = & no_match_data. unsatisfied_predicates ;
227227 let lev_candidate = no_match_data. lev_candidate ;
@@ -523,7 +523,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
523523 let term = pred. skip_binder ( ) . term ;
524524
525525 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+ ) ) ;
527530
528531 bound_span_label ( projection_ty. self_ty ( ) , & obligation, & quiet) ;
529532 Some ( ( obligation, projection_ty. self_ty ( ) ) )
@@ -533,7 +536,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
533536 let self_ty = p. self_ty ( ) ;
534537 let path = p. print_only_trait_path ( ) ;
535538 let obligation = format ! ( "{}: {}" , self_ty, path) ;
536- let quiet = format ! ( "_: {}" , path) ;
539+ let quiet = with_forced_trimmed_paths ! ( format!( "_: {}" , path) ) ;
537540 bound_span_label ( self_ty, & obligation, & quiet) ;
538541 Some ( ( obligation, self_ty) )
539542 }
@@ -636,6 +639,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
636639 let entry = spanned_predicates. entry ( spans) ;
637640 entry. or_insert_with ( || ( path, tr_self_ty, Vec :: new ( ) ) ) . 2 . push ( p) ;
638641 }
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+ }
639652 Some ( _) => unreachable ! ( ) ,
640653 None => ( ) ,
641654 }
@@ -731,9 +744,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
731744 } else {
732745 ( None , None )
733746 } ;
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+ } ) ;
737753 err. set_primary_message ( & primary_message) ;
738754 if let Some ( label) = label {
739755 custom_span_label = true ;
@@ -826,11 +842,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
826842 }
827843 }
828844 } else {
845+ let ty_str =
846+ if ty_str. len ( ) > 50 { String :: new ( ) } else { format ! ( "on `{ty_str}` " ) } ;
829847 err. span_label (
830848 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" ) ,
834850 ) ;
835851 }
836852 } ;
@@ -922,7 +938,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
922938 if def_kind == DefKind :: AssocFn && lev_candidate. fn_has_self_parameter {
923939 err. span_suggestion (
924940 span,
925- & format ! ( "there is a method with a similar name" , ) ,
941+ "there is a method with a similar name" ,
926942 lev_candidate. name ,
927943 Applicability :: MaybeIncorrect ,
928944 ) ;
@@ -966,11 +982,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
966982 // Provide the best span we can. Use the item, if local to crate, else
967983 // the impl, if local to crate (item may be defaulted), else nothing.
968984 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+ } ;
974990
975991 let note_span = if item. def_id . is_local ( ) {
976992 Some ( self . tcx . def_span ( item. def_id ) )
@@ -1015,35 +1031,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10151031 err. note ( & note_str) ;
10161032 }
10171033 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+ }
10471063 }
10481064 CandidateSource :: Trait ( trait_did) => {
10491065 let Some ( item) = self . associated_value ( trait_did, item_name) else { continue } ;
0 commit comments