@@ -347,8 +347,7 @@ impl<'tcx> Ty<'tcx> {
347347impl < ' tcx > TyCtxt < ' tcx > {
348348 pub fn note_and_explain_type_err (
349349 self ,
350- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
351- db : & mut Diagnostic ,
350+ diag : & mut Diagnostic ,
352351 err : & TypeError < ' tcx > ,
353352 cause : & ObligationCause < ' tcx > ,
354353 sp : Span ,
@@ -360,12 +359,12 @@ impl<'tcx> TyCtxt<'tcx> {
360359 ArgumentSorts ( values, _) | Sorts ( values) => {
361360 match ( values. expected . kind ( ) , values. found . kind ( ) ) {
362361 ( ty:: Closure ( ..) , ty:: Closure ( ..) ) => {
363- db . note ( "no two closures, even if identical, have the same type" ) ;
364- db . help ( "consider boxing your closure and/or using it as a trait object" ) ;
362+ diag . note ( "no two closures, even if identical, have the same type" ) ;
363+ diag . help ( "consider boxing your closure and/or using it as a trait object" ) ;
365364 }
366365 ( ty:: Opaque ( ..) , ty:: Opaque ( ..) ) => {
367366 // Issue #63167
368- db . note ( "distinct uses of `impl Trait` result in different opaque types" ) ;
367+ diag . note ( "distinct uses of `impl Trait` result in different opaque types" ) ;
369368 }
370369 ( ty:: Float ( _) , ty:: Infer ( ty:: IntVar ( _) ) )
371370 if let Ok (
@@ -374,7 +373,7 @@ impl<'tcx> TyCtxt<'tcx> {
374373 ) = self . sess . source_map ( ) . span_to_snippet ( sp) =>
375374 {
376375 if snippet. chars ( ) . all ( |c| c. is_digit ( 10 ) || c == '-' || c == '_' ) {
377- db . span_suggestion (
376+ diag . span_suggestion (
378377 sp,
379378 "use a float literal" ,
380379 format ! ( "{}.0" , snippet) ,
@@ -386,30 +385,30 @@ impl<'tcx> TyCtxt<'tcx> {
386385 let generics = self . generics_of ( body_owner_def_id) ;
387386 let e_span = self . def_span ( generics. type_param ( expected, self ) . def_id ) ;
388387 if !sp. contains ( e_span) {
389- db . span_label ( e_span, "expected type parameter" ) ;
388+ diag . span_label ( e_span, "expected type parameter" ) ;
390389 }
391390 let f_span = self . def_span ( generics. type_param ( found, self ) . def_id ) ;
392391 if !sp. contains ( f_span) {
393- db . span_label ( f_span, "found type parameter" ) ;
392+ diag . span_label ( f_span, "found type parameter" ) ;
394393 }
395- db . note (
394+ diag . note (
396395 "a type parameter was expected, but a different one was found; \
397396 you might be missing a type parameter or trait bound",
398397 ) ;
399- db . note (
398+ diag . note (
400399 "for more information, visit \
401400 https://doc.rust-lang.org/book/ch10-02-traits.html\
402401 #traits-as-parameters",
403402 ) ;
404403 }
405404 ( ty:: Projection ( _) , ty:: Projection ( _) ) => {
406- db . note ( "an associated type was expected, but a different one was found" ) ;
405+ diag . note ( "an associated type was expected, but a different one was found" ) ;
407406 }
408407 ( ty:: Param ( p) , ty:: Projection ( proj) ) | ( ty:: Projection ( proj) , ty:: Param ( p) ) => {
409408 let generics = self . generics_of ( body_owner_def_id) ;
410409 let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
411410 if !sp. contains ( p_span) {
412- db . span_label ( p_span, "this type parameter" ) ;
411+ diag . span_label ( p_span, "this type parameter" ) ;
413412 }
414413 let hir = self . hir ( ) ;
415414 let mut note = true ;
@@ -444,26 +443,26 @@ impl<'tcx> TyCtxt<'tcx> {
444443 note = !suggest_constraining_type_param (
445444 self ,
446445 generics,
447- db ,
446+ diag ,
448447 & format ! ( "{}" , proj. self_ty( ) ) ,
449448 & path,
450449 None ,
451450 ) ;
452451 }
453452 if note {
454- db . note ( "you might be missing a type parameter or trait bound" ) ;
453+ diag . note ( "you might be missing a type parameter or trait bound" ) ;
455454 }
456455 }
457456 ( ty:: Param ( p) , ty:: Dynamic ( ..) | ty:: Opaque ( ..) )
458457 | ( ty:: Dynamic ( ..) | ty:: Opaque ( ..) , ty:: Param ( p) ) => {
459458 let generics = self . generics_of ( body_owner_def_id) ;
460459 let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
461460 if !sp. contains ( p_span) {
462- db . span_label ( p_span, "this type parameter" ) ;
461+ diag . span_label ( p_span, "this type parameter" ) ;
463462 }
464- db . help ( "type parameters must be constrained to match other types" ) ;
465- if self . sess . teach ( & db . get_code ( ) . unwrap ( ) ) {
466- db . help (
463+ diag . help ( "type parameters must be constrained to match other types" ) ;
464+ if self . sess . teach ( & diag . get_code ( ) . unwrap ( ) ) {
465+ diag . help (
467466 "given a type parameter `T` and a method `foo`:
468467```
469468trait Trait<T> { fn foo(&self) -> T; }
@@ -489,7 +488,7 @@ impl<T> Trait<T> for X {
489488```" ,
490489 ) ;
491490 }
492- db . note (
491+ diag . note (
493492 "for more information, visit \
494493 https://doc.rust-lang.org/book/ch10-02-traits.html\
495494 #traits-as-parameters",
@@ -499,9 +498,9 @@ impl<T> Trait<T> for X {
499498 let generics = self . generics_of ( body_owner_def_id) ;
500499 let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
501500 if !sp. contains ( p_span) {
502- db . span_label ( p_span, "this type parameter" ) ;
501+ diag . span_label ( p_span, "this type parameter" ) ;
503502 }
504- db . help ( & format ! (
503+ diag . help ( & format ! (
505504 "every closure has a distinct type and so could not always match the \
506505 caller-chosen type of parameter `{}`",
507506 p
@@ -511,12 +510,12 @@ impl<T> Trait<T> for X {
511510 let generics = self . generics_of ( body_owner_def_id) ;
512511 let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
513512 if !sp. contains ( p_span) {
514- db . span_label ( p_span, "this type parameter" ) ;
513+ diag . span_label ( p_span, "this type parameter" ) ;
515514 }
516515 }
517516 ( ty:: Projection ( proj_ty) , _) => {
518517 self . expected_projection (
519- db ,
518+ diag ,
520519 proj_ty,
521520 values,
522521 body_owner_def_id,
@@ -529,19 +528,19 @@ impl<T> Trait<T> for X {
529528 values. found, values. expected,
530529 ) ;
531530 if !( self . suggest_constraining_opaque_associated_type (
532- db ,
531+ diag ,
533532 & msg,
534533 proj_ty,
535534 values. expected ,
536535 ) || self . suggest_constraint (
537- db ,
536+ diag ,
538537 & msg,
539538 body_owner_def_id,
540539 proj_ty,
541540 values. expected ,
542541 ) ) {
543- db . help ( & msg) ;
544- db . note (
542+ diag . help ( & msg) ;
543+ diag . note (
545544 "for more information, visit \
546545 https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
547546 ) ;
@@ -560,7 +559,7 @@ impl<T> Trait<T> for X {
560559 CyclicTy ( ty) => {
561560 // Watch out for various cases of cyclic types and try to explain.
562561 if ty. is_closure ( ) || ty. is_generator ( ) {
563- db . note (
562+ diag . note (
564563 "closures cannot capture themselves or take themselves as argument;\n \
565564 this error may be the result of a recent compiler bug-fix,\n \
566565 see issue #46062 <https://github.com/rust-lang/rust/issues/46062>\n \
@@ -574,19 +573,18 @@ impl<T> Trait<T> for X {
574573 . iter ( )
575574 . filter ( |attr| attr. has_name ( sym:: target_feature) )
576575 . map ( |attr| attr. span ) ;
577- db . note (
576+ diag . note (
578577 "functions with `#[target_feature]` can only be coerced to `unsafe` function pointers"
579578 ) ;
580- db . span_labels ( target_spans, "`#[target_feature]` added here" ) ;
579+ diag . span_labels ( target_spans, "`#[target_feature]` added here" ) ;
581580 }
582581 _ => { }
583582 }
584583 }
585584
586585 fn suggest_constraint (
587586 self ,
588- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
589- db : & mut Diagnostic ,
587+ diag : & mut Diagnostic ,
590588 msg : & str ,
591589 body_owner_def_id : DefId ,
592590 proj_ty : & ty:: ProjectionTy < ' tcx > ,
@@ -623,7 +621,7 @@ impl<T> Trait<T> for X {
623621 }
624622
625623 if self . constrain_generic_bound_associated_type_structured_suggestion (
626- db ,
624+ diag ,
627625 & trait_ref,
628626 pred. bounds ,
629627 & assoc,
@@ -642,7 +640,7 @@ impl<T> Trait<T> for X {
642640 {
643641 // This is type param `A` in `<A as T>::Foo`.
644642 return self . constrain_generic_bound_associated_type_structured_suggestion (
645- db ,
643+ diag ,
646644 & trait_ref,
647645 param. bounds ,
648646 & assoc,
@@ -673,8 +671,7 @@ impl<T> Trait<T> for X {
673671 /// fn that returns the type.
674672 fn expected_projection (
675673 self ,
676- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
677- db : & mut Diagnostic ,
674+ diag : & mut Diagnostic ,
678675 proj_ty : & ty:: ProjectionTy < ' tcx > ,
679676 values : & ExpectedFound < Ty < ' tcx > > ,
680677 body_owner_def_id : DefId ,
@@ -712,41 +709,44 @@ impl<T> Trait<T> for X {
712709 // want the more general suggestion later in this method about "consider constraining
713710 // the associated type or calling a method that returns the associated type".
714711 let point_at_assoc_fn = self . point_at_methods_that_satisfy_associated_type (
715- db ,
712+ diag ,
716713 assoc. container . id ( ) ,
717714 current_method_ident,
718715 proj_ty. item_def_id ,
719716 values. expected ,
720717 ) ;
721718 // Possibly suggest constraining the associated type to conform to the
722719 // found type.
723- if self . suggest_constraint ( db , & msg, body_owner_def_id, proj_ty, values. found )
720+ if self . suggest_constraint ( diag , & msg, body_owner_def_id, proj_ty, values. found )
724721 || point_at_assoc_fn
725722 {
726723 return ;
727724 }
728725 }
729726
730- self . suggest_constraining_opaque_associated_type ( db , & msg, proj_ty, values. found ) ;
727+ self . suggest_constraining_opaque_associated_type ( diag , & msg, proj_ty, values. found ) ;
731728
732- if self . point_at_associated_type ( db , body_owner_def_id, values. found ) {
729+ if self . point_at_associated_type ( diag , body_owner_def_id, values. found ) {
733730 return ;
734731 }
735732
736733 if !impl_comparison {
737734 // Generic suggestion when we can't be more specific.
738735 if callable_scope {
739- db. help ( & format ! ( "{} or calling a method that returns `{}`" , msg, values. expected) ) ;
736+ diag. help ( & format ! (
737+ "{} or calling a method that returns `{}`" ,
738+ msg, values. expected
739+ ) ) ;
740740 } else {
741- db . help ( & msg) ;
741+ diag . help ( & msg) ;
742742 }
743- db . note (
743+ diag . note (
744744 "for more information, visit \
745745 https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
746746 ) ;
747747 }
748- if self . sess . teach ( & db . get_code ( ) . unwrap ( ) ) {
749- db . help (
748+ if self . sess . teach ( & diag . get_code ( ) . unwrap ( ) ) {
749+ diag . help (
750750 "given an associated type `T` and a method `foo`:
751751```
752752trait Trait {
@@ -769,8 +769,7 @@ fn foo(&self) -> Self::T { String::new() }
769769 /// a return type. This can occur when dealing with `TryStream` (#71035).
770770 fn suggest_constraining_opaque_associated_type (
771771 self ,
772- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
773- db : & mut Diagnostic ,
772+ diag : & mut Diagnostic ,
774773 msg : & str ,
775774 proj_ty : & ty:: ProjectionTy < ' tcx > ,
776775 ty : Ty < ' tcx > ,
@@ -790,7 +789,7 @@ fn foo(&self) -> Self::T { String::new() }
790789 let ( trait_ref, assoc_substs) = proj_ty. trait_ref_and_own_substs ( self ) ;
791790
792791 self . constrain_generic_bound_associated_type_structured_suggestion (
793- db ,
792+ diag ,
794793 & trait_ref,
795794 opaque_hir_ty. bounds ,
796795 assoc,
@@ -806,8 +805,7 @@ fn foo(&self) -> Self::T { String::new() }
806805
807806 fn point_at_methods_that_satisfy_associated_type (
808807 self ,
809- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
810- db : & mut Diagnostic ,
808+ diag : & mut Diagnostic ,
811809 assoc_container_id : DefId ,
812810 current_method_ident : Option < Symbol > ,
813811 proj_ty_item_def_id : DefId ,
@@ -854,16 +852,15 @@ fn foo(&self) -> Self::T { String::new() }
854852 for ( sp, label) in methods. into_iter ( ) {
855853 span. push_span_label ( sp, label) ;
856854 }
857- db . span_help ( span, & msg) ;
855+ diag . span_help ( span, & msg) ;
858856 return true ;
859857 }
860858 false
861859 }
862860
863861 fn point_at_associated_type (
864862 self ,
865- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
866- db : & mut Diagnostic ,
863+ diag : & mut Diagnostic ,
867864 body_owner_def_id : DefId ,
868865 found : Ty < ' tcx > ,
869866 ) -> bool {
@@ -887,7 +884,7 @@ fn foo(&self) -> Self::T { String::new() }
887884 if let hir:: Defaultness :: Default { has_value : true } = item. defaultness
888885 {
889886 if self . type_of ( item. id . def_id ) == found {
890- db . span_label (
887+ diag . span_label (
891888 item. span ,
892889 "associated type defaults can't be assumed inside the \
893890 trait defining them",
@@ -907,7 +904,7 @@ fn foo(&self) -> Self::T { String::new() }
907904 for item in & items[ ..] {
908905 if let hir:: AssocItemKind :: Type = item. kind {
909906 if self . type_of ( item. id . def_id ) == found {
910- db . span_label ( item. span , "expected this associated type" ) ;
907+ diag . span_label ( item. span , "expected this associated type" ) ;
911908 return true ;
912909 }
913910 }
@@ -927,8 +924,7 @@ fn foo(&self) -> Self::T { String::new() }
927924 /// type is defined on a supertrait of the one present in the bounds.
928925 fn constrain_generic_bound_associated_type_structured_suggestion (
929926 self ,
930- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
931- db : & mut Diagnostic ,
927+ diag : & mut Diagnostic ,
932928 trait_ref : & ty:: TraitRef < ' tcx > ,
933929 bounds : hir:: GenericBounds < ' _ > ,
934930 assoc : & ty:: AssocItem ,
@@ -958,15 +954,21 @@ fn foo(&self) -> Self::T { String::new() }
958954 _ => return false ,
959955 } ;
960956
961- self . constrain_associated_type_structured_suggestion ( db, span, assoc, assoc_substs, ty, msg)
957+ self . constrain_associated_type_structured_suggestion (
958+ diag,
959+ span,
960+ assoc,
961+ assoc_substs,
962+ ty,
963+ msg,
964+ )
962965 }
963966
964967 /// Given a span corresponding to a bound, provide a structured suggestion to set an
965968 /// associated type to a given type `ty`.
966969 fn constrain_associated_type_structured_suggestion (
967970 self ,
968- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
969- db : & mut Diagnostic ,
971+ diag : & mut Diagnostic ,
970972 span : Span ,
971973 assoc : & ty:: AssocItem ,
972974 assoc_substs : & [ ty:: GenericArg < ' tcx > ] ,
@@ -984,7 +986,7 @@ fn foo(&self) -> Self::T { String::new() }
984986 let item_args = self . format_generic_args ( assoc_substs) ;
985987 ( span. shrink_to_hi ( ) , format ! ( "<{}{} = {}>" , assoc. ident( self ) , item_args, ty) )
986988 } ;
987- db . span_suggestion_verbose ( span, msg, sugg, MaybeIncorrect ) ;
989+ diag . span_suggestion_verbose ( span, msg, sugg, MaybeIncorrect ) ;
988990 return true ;
989991 }
990992 false
0 commit comments