@@ -385,14 +385,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
385
385
} )
386
386
}
387
387
388
- pub ( super ) fn report_ambiguous_assoc_ty (
388
+ pub ( super ) fn report_ambiguous_assoc (
389
389
& self ,
390
390
span : Span ,
391
391
types : & [ String ] ,
392
392
traits : & [ String ] ,
393
393
name : Symbol ,
394
+ kind : ty:: AssocKind ,
394
395
) -> 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}" ) ;
396
399
if self
397
400
. tcx ( )
398
401
. resolutions ( ( ) )
@@ -417,7 +420,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
417
420
span,
418
421
format ! (
419
422
"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 \
421
424
fully-qualified path",
422
425
) ,
423
426
format ! ( "<Type as Trait>::{name}" ) ,
@@ -440,7 +443,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
440
443
span,
441
444
format ! (
442
445
"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 \
444
447
fully-qualified path",
445
448
) ,
446
449
traits. iter ( ) . map ( |trait_str| format ! ( "<Example as {trait_str}>::{name}" ) ) ,
@@ -451,7 +454,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
451
454
err. span_suggestion_verbose (
452
455
span,
453
456
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}` \
455
458
implemented for `{type_str}`, you could use the fully-qualified path",
456
459
) ,
457
460
format ! ( "<{type_str} as Example>::{name}" ) ,
@@ -462,7 +465,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
462
465
err. span_suggestions (
463
466
span,
464
467
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}` \
466
469
implemented for one of the types, you could use the fully-qualified \
467
470
path",
468
471
) ,
@@ -491,7 +494,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
491
494
err. emit ( )
492
495
}
493
496
494
- pub ( crate ) fn complain_about_ambiguous_inherent_assoc_ty (
497
+ pub ( crate ) fn complain_about_ambiguous_inherent_assoc (
495
498
& self ,
496
499
name : Ident ,
497
500
candidates : Vec < DefId > ,
@@ -552,13 +555,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
552
555
}
553
556
554
557
// 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 (
556
559
& self ,
557
560
name : Ident ,
558
561
self_ty : Ty < ' tcx > ,
559
562
candidates : Vec < ( DefId , ( DefId , DefId ) ) > ,
560
563
fulfillment_errors : Vec < FulfillmentError < ' tcx > > ,
561
564
span : Span ,
565
+ kind : ty:: AssocKind ,
562
566
) -> ErrorGuaranteed {
563
567
// FIXME(fmease): This was copied in parts from an old version of `rustc_hir_typeck::method::suggest`.
564
568
// Either
@@ -568,12 +572,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
568
572
569
573
let tcx = self . tcx ( ) ;
570
574
575
+ let kind_str = assoc_kind_str ( kind) ;
571
576
let adt_did = self_ty. ty_adt_def ( ) . map ( |def| def. did ( ) ) ;
572
577
let add_def_label = |err : & mut Diag < ' _ > | {
573
578
if let Some ( did) = adt_did {
574
579
err. span_label (
575
580
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
+ ) ,
577
585
) ;
578
586
}
579
587
} ;
@@ -600,11 +608,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
600
608
self . dcx( ) ,
601
609
name. span,
602
610
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"
604
612
) ;
605
613
err. span_label ( name. span , format ! ( "associated item not found in `{self_ty}`" ) ) ;
606
614
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}" ,
608
616
) ) ;
609
617
add_def_label ( & mut err) ;
610
618
return err. emit ( ) ;
@@ -685,7 +693,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
685
693
686
694
let mut err = self . dcx ( ) . struct_span_err (
687
695
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" )
689
697
) ;
690
698
if !bounds. is_empty ( ) {
691
699
err. note ( format ! (
@@ -695,7 +703,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
695
703
}
696
704
err. span_label (
697
705
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" )
699
707
) ;
700
708
701
709
for ( span, mut bounds) in bound_spans {
@@ -1614,7 +1622,7 @@ fn generics_args_err_extend<'a>(
1614
1622
}
1615
1623
}
1616
1624
1617
- pub ( super ) fn assoc_kind_str ( kind : ty:: AssocKind ) -> & ' static str {
1625
+ pub ( crate ) fn assoc_kind_str ( kind : ty:: AssocKind ) -> & ' static str {
1618
1626
match kind {
1619
1627
ty:: AssocKind :: Fn => "function" ,
1620
1628
ty:: AssocKind :: Const => "constant" ,
0 commit comments