@@ -41,27 +41,19 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
4141 err. downgrade_to_delayed_bug ( ) ;
4242 }
4343
44- if let Ok ( snippet) = self . sess . source_map ( ) . span_to_snippet ( self . span ) {
45- if self . ty . is_fn ( ) {
46- err. span_suggestion (
47- self . span ,
48- "cast the value into a function pointer" ,
49- format ! ( "{} as {}" , snippet, self . cast_ty) ,
50- Applicability :: MachineApplicable ,
51- )
52- . help ( "a function item is zero-sized and needs to be casted into a function pointer to be used in FFI" )
44+ let msg = if self . ty . is_fn ( ) {
45+ err. help ( "a function item is zero-sized and needs to be casted into a function pointer to be used in FFI" )
5346 . note ( "for more information on function items, visit https://doc.rust-lang.org/reference/types/function-item.html" ) ;
47+ "cast the value into a function pointer" . to_string ( )
5448 } else {
55- err. span_suggestion (
56- self . span ,
57- format ! ( "cast the value to `{}`" , self . cast_ty) ,
58- format ! ( "{} as {}" , snippet, self . cast_ty) ,
59- Applicability :: MachineApplicable ,
60- ) ;
61- }
62- } else {
63- err. help ( format ! ( "cast the value into `{}`" , self . cast_ty) ) ;
64- }
49+ format ! ( "cast the value to `{}`" , self . cast_ty)
50+ } ;
51+ err. span_suggestion_verbose (
52+ self . span . shrink_to_hi ( ) ,
53+ msg,
54+ format ! ( " as {}" , snippet, self . cast_ty) ,
55+ Applicability :: MachineApplicable ,
56+ ) ;
6557
6658 err
6759 }
0 commit comments