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+ } ;
34use rustc_hir as hir;
45use rustc_middle:: ty:: { self as ty, AssocItems , AssocKind , TyCtxt } ;
5- use rustc_session:: Session ;
66use rustc_span:: def_id:: DefId ;
77use std:: iter;
88
@@ -541,14 +541,8 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
541541 }
542542 }
543543
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-
550544 /// 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 > ) {
552546 let ( quantifier, bound) = self . get_quantifier_and_bound ( ) ;
553547 let provided_args = self . num_provided_args ( ) ;
554548
@@ -600,7 +594,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
600594 }
601595 }
602596
603- fn suggest ( & self , err : & mut Diag < ' _ > ) {
597+ fn suggest ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
604598 debug ! (
605599 "suggest(self.provided {:?}, self.gen_args.span(): {:?})" ,
606600 self . num_provided_args( ) ,
@@ -628,7 +622,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
628622 /// ```text
629623 /// type Map = HashMap<String>;
630624 /// ```
631- fn suggest_adding_args ( & self , err : & mut Diag < ' _ > ) {
625+ fn suggest_adding_args ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
632626 if self . gen_args . parenthesized != hir:: GenericArgsParentheses :: No {
633627 return ;
634628 }
@@ -647,7 +641,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
647641 }
648642 }
649643
650- fn suggest_adding_lifetime_args ( & self , err : & mut Diag < ' _ > ) {
644+ fn suggest_adding_lifetime_args ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
651645 debug ! ( "suggest_adding_lifetime_args(path_segment: {:?})" , self . path_segment) ;
652646 let num_missing_args = self . num_missing_lifetime_args ( ) ;
653647 let num_params_to_take = num_missing_args;
@@ -701,7 +695,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
701695 }
702696 }
703697
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 > ) {
705699 let num_missing_args = self . num_missing_type_or_const_args ( ) ;
706700 let msg = format ! ( "add missing {} argument{}" , self . kind( ) , pluralize!( num_missing_args) ) ;
707701
@@ -761,7 +755,10 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
761755 /// ```compile_fail
762756 /// Into::into::<Option<_>>(42) // suggests considering `Into::<Option<_>>::into(42)`
763757 /// ```
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+ ) {
765762 let trait_ = match self . tcx . trait_of_item ( self . def_id ) {
766763 Some ( def_id) => def_id,
767764 None => return ,
@@ -817,7 +814,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
817814
818815 fn suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path (
819816 & self ,
820- err : & mut Diag < ' _ > ,
817+ err : & mut Diag < ' _ , impl EmissionGuarantee > ,
821818 qpath : & ' tcx hir:: QPath < ' tcx > ,
822819 msg : String ,
823820 num_assoc_fn_excess_args : usize ,
@@ -850,7 +847,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
850847
851848 fn suggest_moving_args_from_assoc_fn_to_trait_for_method_call (
852849 & self ,
853- err : & mut Diag < ' _ > ,
850+ err : & mut Diag < ' _ , impl EmissionGuarantee > ,
854851 trait_def_id : DefId ,
855852 expr : & ' tcx hir:: Expr < ' tcx > ,
856853 msg : String ,
@@ -904,7 +901,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
904901 /// ```text
905902 /// type Map = HashMap<String, String, String, String>;
906903 /// ```
907- fn suggest_removing_args_or_generics ( & self , err : & mut Diag < ' _ > ) {
904+ fn suggest_removing_args_or_generics ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
908905 let num_provided_lt_args = self . num_provided_lifetime_args ( ) ;
909906 let num_provided_type_const_args = self . num_provided_type_or_const_args ( ) ;
910907 let unbound_types = self . get_unbound_associated_types ( ) ;
@@ -922,7 +919,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
922919 let provided_args_matches_unbound_traits =
923920 unbound_types. len ( ) == num_redundant_type_or_const_args;
924921
925- let remove_lifetime_args = |err : & mut Diag < ' _ > | {
922+ let remove_lifetime_args = |err : & mut Diag < ' _ , _ > | {
926923 let mut lt_arg_spans = Vec :: new ( ) ;
927924 let mut found_redundant = false ;
928925 for arg in self . gen_args . args {
@@ -963,7 +960,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
963960 ) ;
964961 } ;
965962
966- let remove_type_or_const_args = |err : & mut Diag < ' _ > | {
963+ let remove_type_or_const_args = |err : & mut Diag < ' _ , _ > | {
967964 let mut gen_arg_spans = Vec :: new ( ) ;
968965 let mut found_redundant = false ;
969966 for arg in self . gen_args . args {
@@ -1060,7 +1057,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
10601057 }
10611058
10621059 /// Builds the `type defined here` message.
1063- fn show_definition ( & self , err : & mut Diag < ' _ > ) {
1060+ fn show_definition ( & self , err : & mut Diag < ' _ , impl EmissionGuarantee > ) {
10641061 let mut spans: MultiSpan = if let Some ( def_span) = self . tcx . def_ident_span ( self . def_id ) {
10651062 if self . tcx . sess . source_map ( ) . is_span_accessible ( def_span) {
10661063 def_span. into ( )
@@ -1111,7 +1108,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
11111108 }
11121109
11131110 /// 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 > ) {
11151112 if !self . is_synth_provided ( ) {
11161113 return ;
11171114 }
@@ -1120,17 +1117,16 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
11201117 }
11211118}
11221119
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 ) ;
11341130
11351131 self . notify ( & mut err) ;
11361132 self . suggest ( & mut err) ;
0 commit comments