@@ -385,14 +385,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
385385 } )
386386 }
387387
388- pub ( super ) fn report_ambiguous_assoc_ty (
388+ pub ( super ) fn report_ambiguous_assoc (
389389 & self ,
390390 span : Span ,
391391 types : & [ String ] ,
392392 traits : & [ String ] ,
393393 name : Symbol ,
394+ kind : ty:: AssocKind ,
394395 ) -> ErrorGuaranteed {
395- let mut err = struct_span_code_err ! ( self . dcx( ) , span, E0223 , "ambiguous associated type" ) ;
396+ let kind_str = assoc_kind_str ( kind) ;
397+ let mut err =
398+ struct_span_code_err ! ( self . dcx( ) , span, E0223 , "ambiguous associated {kind_str}" ) ;
396399 if self
397400 . tcx ( )
398401 . resolutions ( ( ) )
@@ -417,7 +420,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
417420 span,
418421 format ! (
419422 "if there were a type named `Type` that implements a trait named \
420- `Trait` with associated type `{name}`, you could use the \
423+ `Trait` with associated {kind_str} `{name}`, you could use the \
421424 fully-qualified path",
422425 ) ,
423426 format ! ( "<Type as Trait>::{name}" ) ,
@@ -440,7 +443,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
440443 span,
441444 format ! (
442445 "if there were a type named `Example` that implemented one of the \
443- traits with associated type `{name}`, you could use the \
446+ traits with associated {kind_str} `{name}`, you could use the \
444447 fully-qualified path",
445448 ) ,
446449 traits. iter ( ) . map ( |trait_str| format ! ( "<Example as {trait_str}>::{name}" ) ) ,
@@ -451,7 +454,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
451454 err. span_suggestion_verbose (
452455 span,
453456 format ! (
454- "if there were a trait named `Example` with associated type `{name}` \
457+ "if there were a trait named `Example` with associated {kind_str} `{name}` \
455458 implemented for `{type_str}`, you could use the fully-qualified path",
456459 ) ,
457460 format ! ( "<{type_str} as Example>::{name}" ) ,
@@ -462,7 +465,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
462465 err. span_suggestions (
463466 span,
464467 format ! (
465- "if there were a trait named `Example` with associated type `{name}` \
468+ "if there were a trait named `Example` with associated {kind_str} `{name}` \
466469 implemented for one of the types, you could use the fully-qualified \
467470 path",
468471 ) ,
@@ -491,7 +494,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
491494 err. emit ( )
492495 }
493496
494- pub ( crate ) fn complain_about_ambiguous_inherent_assoc_ty (
497+ pub ( crate ) fn complain_about_ambiguous_inherent_assoc (
495498 & self ,
496499 name : Ident ,
497500 candidates : Vec < DefId > ,
@@ -552,13 +555,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
552555 }
553556
554557 // FIXME(inherent_associated_types): Find similarly named associated types and suggest them.
555- pub ( crate ) fn complain_about_inherent_assoc_ty_not_found (
558+ pub ( crate ) fn complain_about_inherent_assoc_not_found (
556559 & self ,
557560 name : Ident ,
558561 self_ty : Ty < ' tcx > ,
559562 candidates : Vec < ( DefId , ( DefId , DefId ) ) > ,
560563 fulfillment_errors : Vec < FulfillmentError < ' tcx > > ,
561564 span : Span ,
565+ kind : ty:: AssocKind ,
562566 ) -> ErrorGuaranteed {
563567 // FIXME(fmease): This was copied in parts from an old version of `rustc_hir_typeck::method::suggest`.
564568 // Either
@@ -568,12 +572,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
568572
569573 let tcx = self . tcx ( ) ;
570574
575+ let kind_str = assoc_kind_str ( kind) ;
571576 let adt_did = self_ty. ty_adt_def ( ) . map ( |def| def. did ( ) ) ;
572577 let add_def_label = |err : & mut Diag < ' _ > | {
573578 if let Some ( did) = adt_did {
574579 err. span_label (
575580 tcx. def_span ( did) ,
576- format ! ( "associated item `{name}` not found for this {}" , tcx. def_descr( did) ) ,
581+ format ! (
582+ "associated {kind_str} `{name}` not found for this {}" ,
583+ tcx. def_descr( did)
584+ ) ,
577585 ) ;
578586 }
579587 } ;
@@ -600,11 +608,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
600608 self . dcx( ) ,
601609 name. span,
602610 E0220 ,
603- "associated type `{name}` not found for `{self_ty}` in the current scope"
611+ "associated {kind_str} `{name}` not found for `{self_ty}` in the current scope"
604612 ) ;
605613 err. span_label ( name. span , format ! ( "associated item not found in `{self_ty}`" ) ) ;
606614 err. note ( format ! (
607- "the associated type was found for\n {type_candidates}{additional_types}" ,
615+ "the associated {kind_str} was found for\n {type_candidates}{additional_types}" ,
608616 ) ) ;
609617 add_def_label ( & mut err) ;
610618 return err. emit ( ) ;
@@ -685,7 +693,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
685693
686694 let mut err = self . dcx ( ) . struct_span_err (
687695 name. span ,
688- format ! ( "the associated type `{name}` exists for `{self_ty}`, but its trait bounds were not satisfied" )
696+ format ! ( "the associated {kind_str} `{name}` exists for `{self_ty}`, but its trait bounds were not satisfied" )
689697 ) ;
690698 if !bounds. is_empty ( ) {
691699 err. note ( format ! (
@@ -695,7 +703,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
695703 }
696704 err. span_label (
697705 name. span ,
698- format ! ( "associated type cannot be referenced on `{self_ty}` due to unsatisfied trait bounds" )
706+ format ! ( "associated {kind_str} cannot be referenced on `{self_ty}` due to unsatisfied trait bounds" )
699707 ) ;
700708
701709 for ( span, mut bounds) in bound_spans {
@@ -1614,7 +1622,7 @@ fn generics_args_err_extend<'a>(
16141622 }
16151623}
16161624
1617- pub ( super ) fn assoc_kind_str ( kind : ty:: AssocKind ) -> & ' static str {
1625+ pub ( crate ) fn assoc_kind_str ( kind : ty:: AssocKind ) -> & ' static str {
16181626 match kind {
16191627 ty:: AssocKind :: Fn => "function" ,
16201628 ty:: AssocKind :: Const => "constant" ,
0 commit comments