1- use crate :: structured_errors:: StructuredDiagnostic ;
2- use rustc_errors:: { Applicability , DiagnosticBuilder , DiagnosticId , ErrorGuaranteed } ;
1+ use crate :: { errors , structured_errors:: StructuredDiagnostic } ;
2+ use rustc_errors:: { DiagnosticBuilder , DiagnosticId , ErrorGuaranteed } ;
33use rustc_middle:: ty:: { Ty , TypeVisitableExt } ;
44use rustc_session:: Session ;
55use rustc_span:: Span ;
@@ -21,27 +21,26 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
2121 }
2222
2323 fn diagnostic_common ( & self ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
24- let mut err = self . sess . struct_span_err_with_code (
25- self . span ,
26- & format ! ( "can't pass `{}` to variadic function" , self . ty) ,
27- self . code ( ) ,
28- ) ;
24+ let ( sugg_span, replace, help) =
25+ if let Ok ( snippet) = self . sess . source_map ( ) . span_to_snippet ( self . span ) {
26+ ( Some ( self . span ) , format ! ( "{} as {}" , snippet, self . cast_ty) , None )
27+ } else {
28+ ( None , "" . to_string ( ) , Some ( ( ) ) )
29+ } ;
30+
31+ let mut err = self . sess . create_err ( errors:: PassToVariadicFunction {
32+ span : self . span ,
33+ ty : self . ty ,
34+ cast_ty : self . cast_ty ,
35+ help,
36+ replace,
37+ sugg_span,
38+ } ) ;
2939
3040 if self . ty . references_error ( ) {
3141 err. downgrade_to_delayed_bug ( ) ;
3242 }
3343
34- if let Ok ( snippet) = self . sess . source_map ( ) . span_to_snippet ( self . span ) {
35- err. span_suggestion (
36- self . span ,
37- & format ! ( "cast the value to `{}`" , self . cast_ty) ,
38- format ! ( "{} as {}" , snippet, self . cast_ty) ,
39- Applicability :: MachineApplicable ,
40- ) ;
41- } else {
42- err. help ( & format ! ( "cast the value to `{}`" , self . cast_ty) ) ;
43- }
44-
4544 err
4645 }
4746
0 commit comments