@@ -347,8 +347,7 @@ impl<'tcx> Ty<'tcx> {
347
347
impl < ' tcx > TyCtxt < ' tcx > {
348
348
pub fn note_and_explain_type_err (
349
349
self ,
350
- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
351
- db : & mut Diagnostic ,
350
+ diag : & mut Diagnostic ,
352
351
err : & TypeError < ' tcx > ,
353
352
cause : & ObligationCause < ' tcx > ,
354
353
sp : Span ,
@@ -360,12 +359,12 @@ impl<'tcx> TyCtxt<'tcx> {
360
359
ArgumentSorts ( values, _) | Sorts ( values) => {
361
360
match ( values. expected . kind ( ) , values. found . kind ( ) ) {
362
361
( 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" ) ;
365
364
}
366
365
( ty:: Opaque ( ..) , ty:: Opaque ( ..) ) => {
367
366
// 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" ) ;
369
368
}
370
369
( ty:: Float ( _) , ty:: Infer ( ty:: IntVar ( _) ) )
371
370
if let Ok (
@@ -374,7 +373,7 @@ impl<'tcx> TyCtxt<'tcx> {
374
373
) = self . sess . source_map ( ) . span_to_snippet ( sp) =>
375
374
{
376
375
if snippet. chars ( ) . all ( |c| c. is_digit ( 10 ) || c == '-' || c == '_' ) {
377
- db . span_suggestion (
376
+ diag . span_suggestion (
378
377
sp,
379
378
"use a float literal" ,
380
379
format ! ( "{}.0" , snippet) ,
@@ -386,30 +385,30 @@ impl<'tcx> TyCtxt<'tcx> {
386
385
let generics = self . generics_of ( body_owner_def_id) ;
387
386
let e_span = self . def_span ( generics. type_param ( expected, self ) . def_id ) ;
388
387
if !sp. contains ( e_span) {
389
- db . span_label ( e_span, "expected type parameter" ) ;
388
+ diag . span_label ( e_span, "expected type parameter" ) ;
390
389
}
391
390
let f_span = self . def_span ( generics. type_param ( found, self ) . def_id ) ;
392
391
if !sp. contains ( f_span) {
393
- db . span_label ( f_span, "found type parameter" ) ;
392
+ diag . span_label ( f_span, "found type parameter" ) ;
394
393
}
395
- db . note (
394
+ diag . note (
396
395
"a type parameter was expected, but a different one was found; \
397
396
you might be missing a type parameter or trait bound",
398
397
) ;
399
- db . note (
398
+ diag . note (
400
399
"for more information, visit \
401
400
https://doc.rust-lang.org/book/ch10-02-traits.html\
402
401
#traits-as-parameters",
403
402
) ;
404
403
}
405
404
( 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" ) ;
407
406
}
408
407
( ty:: Param ( p) , ty:: Projection ( proj) ) | ( ty:: Projection ( proj) , ty:: Param ( p) ) => {
409
408
let generics = self . generics_of ( body_owner_def_id) ;
410
409
let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
411
410
if !sp. contains ( p_span) {
412
- db . span_label ( p_span, "this type parameter" ) ;
411
+ diag . span_label ( p_span, "this type parameter" ) ;
413
412
}
414
413
let hir = self . hir ( ) ;
415
414
let mut note = true ;
@@ -444,26 +443,26 @@ impl<'tcx> TyCtxt<'tcx> {
444
443
note = !suggest_constraining_type_param (
445
444
self ,
446
445
generics,
447
- db ,
446
+ diag ,
448
447
& format ! ( "{}" , proj. self_ty( ) ) ,
449
448
& path,
450
449
None ,
451
450
) ;
452
451
}
453
452
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" ) ;
455
454
}
456
455
}
457
456
( ty:: Param ( p) , ty:: Dynamic ( ..) | ty:: Opaque ( ..) )
458
457
| ( ty:: Dynamic ( ..) | ty:: Opaque ( ..) , ty:: Param ( p) ) => {
459
458
let generics = self . generics_of ( body_owner_def_id) ;
460
459
let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
461
460
if !sp. contains ( p_span) {
462
- db . span_label ( p_span, "this type parameter" ) ;
461
+ diag . span_label ( p_span, "this type parameter" ) ;
463
462
}
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 (
467
466
"given a type parameter `T` and a method `foo`:
468
467
```
469
468
trait Trait<T> { fn foo(&self) -> T; }
@@ -489,7 +488,7 @@ impl<T> Trait<T> for X {
489
488
```" ,
490
489
) ;
491
490
}
492
- db . note (
491
+ diag . note (
493
492
"for more information, visit \
494
493
https://doc.rust-lang.org/book/ch10-02-traits.html\
495
494
#traits-as-parameters",
@@ -499,9 +498,9 @@ impl<T> Trait<T> for X {
499
498
let generics = self . generics_of ( body_owner_def_id) ;
500
499
let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
501
500
if !sp. contains ( p_span) {
502
- db . span_label ( p_span, "this type parameter" ) ;
501
+ diag . span_label ( p_span, "this type parameter" ) ;
503
502
}
504
- db . help ( & format ! (
503
+ diag . help ( & format ! (
505
504
"every closure has a distinct type and so could not always match the \
506
505
caller-chosen type of parameter `{}`",
507
506
p
@@ -511,12 +510,12 @@ impl<T> Trait<T> for X {
511
510
let generics = self . generics_of ( body_owner_def_id) ;
512
511
let p_span = self . def_span ( generics. type_param ( p, self ) . def_id ) ;
513
512
if !sp. contains ( p_span) {
514
- db . span_label ( p_span, "this type parameter" ) ;
513
+ diag . span_label ( p_span, "this type parameter" ) ;
515
514
}
516
515
}
517
516
( ty:: Projection ( proj_ty) , _) => {
518
517
self . expected_projection (
519
- db ,
518
+ diag ,
520
519
proj_ty,
521
520
values,
522
521
body_owner_def_id,
@@ -529,19 +528,19 @@ impl<T> Trait<T> for X {
529
528
values. found, values. expected,
530
529
) ;
531
530
if !( self . suggest_constraining_opaque_associated_type (
532
- db ,
531
+ diag ,
533
532
& msg,
534
533
proj_ty,
535
534
values. expected ,
536
535
) || self . suggest_constraint (
537
- db ,
536
+ diag ,
538
537
& msg,
539
538
body_owner_def_id,
540
539
proj_ty,
541
540
values. expected ,
542
541
) ) {
543
- db . help ( & msg) ;
544
- db . note (
542
+ diag . help ( & msg) ;
543
+ diag . note (
545
544
"for more information, visit \
546
545
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
547
546
) ;
@@ -560,7 +559,7 @@ impl<T> Trait<T> for X {
560
559
CyclicTy ( ty) => {
561
560
// Watch out for various cases of cyclic types and try to explain.
562
561
if ty. is_closure ( ) || ty. is_generator ( ) {
563
- db . note (
562
+ diag . note (
564
563
"closures cannot capture themselves or take themselves as argument;\n \
565
564
this error may be the result of a recent compiler bug-fix,\n \
566
565
see issue #46062 <https://github.com/rust-lang/rust/issues/46062>\n \
@@ -574,19 +573,18 @@ impl<T> Trait<T> for X {
574
573
. iter ( )
575
574
. filter ( |attr| attr. has_name ( sym:: target_feature) )
576
575
. map ( |attr| attr. span ) ;
577
- db . note (
576
+ diag . note (
578
577
"functions with `#[target_feature]` can only be coerced to `unsafe` function pointers"
579
578
) ;
580
- db . span_labels ( target_spans, "`#[target_feature]` added here" ) ;
579
+ diag . span_labels ( target_spans, "`#[target_feature]` added here" ) ;
581
580
}
582
581
_ => { }
583
582
}
584
583
}
585
584
586
585
fn suggest_constraint (
587
586
self ,
588
- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
589
- db : & mut Diagnostic ,
587
+ diag : & mut Diagnostic ,
590
588
msg : & str ,
591
589
body_owner_def_id : DefId ,
592
590
proj_ty : & ty:: ProjectionTy < ' tcx > ,
@@ -623,7 +621,7 @@ impl<T> Trait<T> for X {
623
621
}
624
622
625
623
if self . constrain_generic_bound_associated_type_structured_suggestion (
626
- db ,
624
+ diag ,
627
625
& trait_ref,
628
626
pred. bounds ,
629
627
& assoc,
@@ -642,7 +640,7 @@ impl<T> Trait<T> for X {
642
640
{
643
641
// This is type param `A` in `<A as T>::Foo`.
644
642
return self . constrain_generic_bound_associated_type_structured_suggestion (
645
- db ,
643
+ diag ,
646
644
& trait_ref,
647
645
param. bounds ,
648
646
& assoc,
@@ -673,8 +671,7 @@ impl<T> Trait<T> for X {
673
671
/// fn that returns the type.
674
672
fn expected_projection (
675
673
self ,
676
- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
677
- db : & mut Diagnostic ,
674
+ diag : & mut Diagnostic ,
678
675
proj_ty : & ty:: ProjectionTy < ' tcx > ,
679
676
values : & ExpectedFound < Ty < ' tcx > > ,
680
677
body_owner_def_id : DefId ,
@@ -712,41 +709,44 @@ impl<T> Trait<T> for X {
712
709
// want the more general suggestion later in this method about "consider constraining
713
710
// the associated type or calling a method that returns the associated type".
714
711
let point_at_assoc_fn = self . point_at_methods_that_satisfy_associated_type (
715
- db ,
712
+ diag ,
716
713
assoc. container . id ( ) ,
717
714
current_method_ident,
718
715
proj_ty. item_def_id ,
719
716
values. expected ,
720
717
) ;
721
718
// Possibly suggest constraining the associated type to conform to the
722
719
// 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 )
724
721
|| point_at_assoc_fn
725
722
{
726
723
return ;
727
724
}
728
725
}
729
726
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 ) ;
731
728
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 ) {
733
730
return ;
734
731
}
735
732
736
733
if !impl_comparison {
737
734
// Generic suggestion when we can't be more specific.
738
735
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
+ ) ) ;
740
740
} else {
741
- db . help ( & msg) ;
741
+ diag . help ( & msg) ;
742
742
}
743
- db . note (
743
+ diag . note (
744
744
"for more information, visit \
745
745
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
746
746
) ;
747
747
}
748
- if self . sess . teach ( & db . get_code ( ) . unwrap ( ) ) {
749
- db . help (
748
+ if self . sess . teach ( & diag . get_code ( ) . unwrap ( ) ) {
749
+ diag . help (
750
750
"given an associated type `T` and a method `foo`:
751
751
```
752
752
trait Trait {
@@ -769,8 +769,7 @@ fn foo(&self) -> Self::T { String::new() }
769
769
/// a return type. This can occur when dealing with `TryStream` (#71035).
770
770
fn suggest_constraining_opaque_associated_type (
771
771
self ,
772
- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
773
- db : & mut Diagnostic ,
772
+ diag : & mut Diagnostic ,
774
773
msg : & str ,
775
774
proj_ty : & ty:: ProjectionTy < ' tcx > ,
776
775
ty : Ty < ' tcx > ,
@@ -790,7 +789,7 @@ fn foo(&self) -> Self::T { String::new() }
790
789
let ( trait_ref, assoc_substs) = proj_ty. trait_ref_and_own_substs ( self ) ;
791
790
792
791
self . constrain_generic_bound_associated_type_structured_suggestion (
793
- db ,
792
+ diag ,
794
793
& trait_ref,
795
794
opaque_hir_ty. bounds ,
796
795
assoc,
@@ -806,8 +805,7 @@ fn foo(&self) -> Self::T { String::new() }
806
805
807
806
fn point_at_methods_that_satisfy_associated_type (
808
807
self ,
809
- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
810
- db : & mut Diagnostic ,
808
+ diag : & mut Diagnostic ,
811
809
assoc_container_id : DefId ,
812
810
current_method_ident : Option < Symbol > ,
813
811
proj_ty_item_def_id : DefId ,
@@ -854,16 +852,15 @@ fn foo(&self) -> Self::T { String::new() }
854
852
for ( sp, label) in methods. into_iter ( ) {
855
853
span. push_span_label ( sp, label) ;
856
854
}
857
- db . span_help ( span, & msg) ;
855
+ diag . span_help ( span, & msg) ;
858
856
return true ;
859
857
}
860
858
false
861
859
}
862
860
863
861
fn point_at_associated_type (
864
862
self ,
865
- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
866
- db : & mut Diagnostic ,
863
+ diag : & mut Diagnostic ,
867
864
body_owner_def_id : DefId ,
868
865
found : Ty < ' tcx > ,
869
866
) -> bool {
@@ -887,7 +884,7 @@ fn foo(&self) -> Self::T { String::new() }
887
884
if let hir:: Defaultness :: Default { has_value : true } = item. defaultness
888
885
{
889
886
if self . type_of ( item. id . def_id ) == found {
890
- db . span_label (
887
+ diag . span_label (
891
888
item. span ,
892
889
"associated type defaults can't be assumed inside the \
893
890
trait defining them",
@@ -907,7 +904,7 @@ fn foo(&self) -> Self::T { String::new() }
907
904
for item in & items[ ..] {
908
905
if let hir:: AssocItemKind :: Type = item. kind {
909
906
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" ) ;
911
908
return true ;
912
909
}
913
910
}
@@ -927,8 +924,7 @@ fn foo(&self) -> Self::T { String::new() }
927
924
/// type is defined on a supertrait of the one present in the bounds.
928
925
fn constrain_generic_bound_associated_type_structured_suggestion (
929
926
self ,
930
- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
931
- db : & mut Diagnostic ,
927
+ diag : & mut Diagnostic ,
932
928
trait_ref : & ty:: TraitRef < ' tcx > ,
933
929
bounds : hir:: GenericBounds < ' _ > ,
934
930
assoc : & ty:: AssocItem ,
@@ -958,15 +954,21 @@ fn foo(&self) -> Self::T { String::new() }
958
954
_ => return false ,
959
955
} ;
960
956
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
+ )
962
965
}
963
966
964
967
/// Given a span corresponding to a bound, provide a structured suggestion to set an
965
968
/// associated type to a given type `ty`.
966
969
fn constrain_associated_type_structured_suggestion (
967
970
self ,
968
- // FIXME(eddyb) rename this since it's no longer a `DiagnosticBuilder`.
969
- db : & mut Diagnostic ,
971
+ diag : & mut Diagnostic ,
970
972
span : Span ,
971
973
assoc : & ty:: AssocItem ,
972
974
assoc_substs : & [ ty:: GenericArg < ' tcx > ] ,
@@ -984,7 +986,7 @@ fn foo(&self) -> Self::T { String::new() }
984
986
let item_args = self . format_generic_args ( assoc_substs) ;
985
987
( span. shrink_to_hi ( ) , format ! ( "<{}{} = {}>" , assoc. ident( self ) , item_args, ty) )
986
988
} ;
987
- db . span_suggestion_verbose ( span, msg, sugg, MaybeIncorrect ) ;
989
+ diag . span_suggestion_verbose ( span, msg, sugg, MaybeIncorrect ) ;
988
990
return true ;
989
991
}
990
992
false
0 commit comments