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 } ;
3
3
use rustc_middle:: ty:: { Ty , TypeVisitableExt } ;
4
4
use rustc_session:: Session ;
5
5
use rustc_span:: Span ;
@@ -21,27 +21,26 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
21
21
}
22
22
23
23
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
+ } ) ;
29
39
30
40
if self . ty . references_error ( ) {
31
41
err. downgrade_to_delayed_bug ( ) ;
32
42
}
33
43
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
-
45
44
err
46
45
}
47
46
0 commit comments