1
- use crate :: structured_errors:: StructuredDiag ;
2
- use rustc_errors:: { codes:: * , pluralize, Applicability , Diag , MultiSpan } ;
1
+ use rustc_errors:: {
2
+ codes:: * , pluralize, Applicability , Diag , Diagnostic , EmissionGuarantee , MultiSpan ,
3
+ } ;
3
4
use rustc_hir as hir;
4
5
use rustc_middle:: ty:: { self as ty, AssocItems , AssocKind , TyCtxt } ;
5
- use rustc_session:: Session ;
6
6
use rustc_span:: def_id:: DefId ;
7
7
use std:: iter;
8
8
@@ -541,14 +541,8 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
541
541
}
542
542
}
543
543
544
- fn start_diagnostics ( & self ) -> Diag < ' tcx > {
545
- let span = self . path_segment . ident . span ;
546
- let msg = self . create_error_message ( ) ;
547
- self . tcx . dcx ( ) . struct_span_err ( span, msg) . with_code ( self . code ( ) )
548
- }
549
-
550
544
/// Builds the `expected 1 type argument / supplied 2 type arguments` message.
551
- fn notify ( & self , err : & mut Diag < ' _ > ) {
545
+ fn notify ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
552
546
let ( quantifier, bound) = self . get_quantifier_and_bound ( ) ;
553
547
let provided_args = self . num_provided_args ( ) ;
554
548
@@ -600,7 +594,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
600
594
}
601
595
}
602
596
603
- fn suggest ( & self , err : & mut Diag < ' _ > ) {
597
+ fn suggest ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
604
598
debug ! (
605
599
"suggest(self.provided {:?}, self.gen_args.span(): {:?})" ,
606
600
self . num_provided_args( ) ,
@@ -628,7 +622,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
628
622
/// ```text
629
623
/// type Map = HashMap<String>;
630
624
/// ```
631
- fn suggest_adding_args ( & self , err : & mut Diag < ' _ > ) {
625
+ fn suggest_adding_args ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
632
626
if self . gen_args . parenthesized != hir:: GenericArgsParentheses :: No {
633
627
return ;
634
628
}
@@ -647,7 +641,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
647
641
}
648
642
}
649
643
650
- fn suggest_adding_lifetime_args ( & self , err : & mut Diag < ' _ > ) {
644
+ fn suggest_adding_lifetime_args ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
651
645
debug ! ( "suggest_adding_lifetime_args(path_segment: {:?})" , self . path_segment) ;
652
646
let num_missing_args = self . num_missing_lifetime_args ( ) ;
653
647
let num_params_to_take = num_missing_args;
@@ -701,7 +695,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
701
695
}
702
696
}
703
697
704
- fn suggest_adding_type_and_const_args ( & self , err : & mut Diag < ' _ > ) {
698
+ fn suggest_adding_type_and_const_args ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
705
699
let num_missing_args = self . num_missing_type_or_const_args ( ) ;
706
700
let msg = format ! ( "add missing {} argument{}" , self . kind( ) , pluralize!( num_missing_args) ) ;
707
701
@@ -761,7 +755,10 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
761
755
/// ```compile_fail
762
756
/// Into::into::<Option<_>>(42) // suggests considering `Into::<Option<_>>::into(42)`
763
757
/// ```
764
- fn suggest_moving_args_from_assoc_fn_to_trait ( & self , err : & mut Diag < ' _ > ) {
758
+ fn suggest_moving_args_from_assoc_fn_to_trait (
759
+ & self ,
760
+ err : & mut Diag < ' _ , impl EmissionGuarantee > ,
761
+ ) {
765
762
let trait_ = match self . tcx . trait_of_item ( self . def_id ) {
766
763
Some ( def_id) => def_id,
767
764
None => return ,
@@ -817,7 +814,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
817
814
818
815
fn suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path (
819
816
& self ,
820
- err : & mut Diag < ' _ > ,
817
+ err : & mut Diag < ' _ , impl EmissionGuarantee > ,
821
818
qpath : & ' tcx hir:: QPath < ' tcx > ,
822
819
msg : String ,
823
820
num_assoc_fn_excess_args : usize ,
@@ -850,7 +847,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
850
847
851
848
fn suggest_moving_args_from_assoc_fn_to_trait_for_method_call (
852
849
& self ,
853
- err : & mut Diag < ' _ > ,
850
+ err : & mut Diag < ' _ , impl EmissionGuarantee > ,
854
851
trait_def_id : DefId ,
855
852
expr : & ' tcx hir:: Expr < ' tcx > ,
856
853
msg : String ,
@@ -904,7 +901,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
904
901
/// ```text
905
902
/// type Map = HashMap<String, String, String, String>;
906
903
/// ```
907
- fn suggest_removing_args_or_generics ( & self , err : & mut Diag < ' _ > ) {
904
+ fn suggest_removing_args_or_generics ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
908
905
let num_provided_lt_args = self . num_provided_lifetime_args ( ) ;
909
906
let num_provided_type_const_args = self . num_provided_type_or_const_args ( ) ;
910
907
let unbound_types = self . get_unbound_associated_types ( ) ;
@@ -922,7 +919,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
922
919
let provided_args_matches_unbound_traits =
923
920
unbound_types. len ( ) == num_redundant_type_or_const_args;
924
921
925
- let remove_lifetime_args = |err : & mut Diag < ' _ > | {
922
+ let remove_lifetime_args = |err : & mut Diag < ' _ , _ > | {
926
923
let mut lt_arg_spans = Vec :: new ( ) ;
927
924
let mut found_redundant = false ;
928
925
for arg in self . gen_args . args {
@@ -963,7 +960,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
963
960
) ;
964
961
} ;
965
962
966
- let remove_type_or_const_args = |err : & mut Diag < ' _ > | {
963
+ let remove_type_or_const_args = |err : & mut Diag < ' _ , _ > | {
967
964
let mut gen_arg_spans = Vec :: new ( ) ;
968
965
let mut found_redundant = false ;
969
966
for arg in self . gen_args . args {
@@ -1060,7 +1057,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
1060
1057
}
1061
1058
1062
1059
/// Builds the `type defined here` message.
1063
- fn show_definition ( & self , err : & mut Diag < ' _ > ) {
1060
+ fn show_definition ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
1064
1061
let mut spans: MultiSpan = if let Some ( def_span) = self . tcx . def_ident_span ( self . def_id ) {
1065
1062
if self . tcx . sess . source_map ( ) . is_span_accessible ( def_span) {
1066
1063
def_span. into ( )
@@ -1111,7 +1108,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
1111
1108
}
1112
1109
1113
1110
/// Add note if `impl Trait` is explicitly specified.
1114
- fn note_synth_provided ( & self , err : & mut Diag < ' _ > ) {
1111
+ fn note_synth_provided ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
1115
1112
if !self . is_synth_provided ( ) {
1116
1113
return ;
1117
1114
}
@@ -1120,17 +1117,16 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
1120
1117
}
1121
1118
}
1122
1119
1123
- impl < ' tcx > StructuredDiag < ' tcx > for WrongNumberOfGenericArgs < ' _ , ' tcx > {
1124
- fn session ( & self ) -> & Session {
1125
- self . tcx . sess
1126
- }
1127
-
1128
- fn code ( & self ) -> ErrCode {
1129
- E0107
1130
- }
1131
-
1132
- fn diagnostic_common ( & self ) -> Diag < ' tcx > {
1133
- let mut err = self . start_diagnostics ( ) ;
1120
+ impl < ' a , G : EmissionGuarantee > Diagnostic < ' a , G > for WrongNumberOfGenericArgs < ' _ , ' _ > {
1121
+ fn into_diag (
1122
+ self ,
1123
+ dcx : rustc_errors:: DiagCtxtHandle < ' a > ,
1124
+ level : rustc_errors:: Level ,
1125
+ ) -> Diag < ' a , G > {
1126
+ let msg = self . create_error_message ( ) ;
1127
+ let mut err = Diag :: new ( dcx, level, msg) ;
1128
+ err. code ( E0107 ) ;
1129
+ err. span ( self . path_segment . ident . span ) ;
1134
1130
1135
1131
self . notify ( & mut err) ;
1136
1132
self . suggest ( & mut err) ;
0 commit comments