1 use crate::structured_errors
::StructuredDiagnostic
;
2 use rustc_errors
::{Applicability, DiagnosticBuilder, DiagnosticId, ErrorGuaranteed}
;
3 use rustc_middle
::ty
::{Ty, TypeFoldable}
;
4 use rustc_session
::Session
;
7 pub struct MissingCastForVariadicArg
<'tcx
, 's
> {
8 pub sess
: &'tcx Session
,
14 impl<'tcx
> StructuredDiagnostic
<'tcx
> for MissingCastForVariadicArg
<'tcx
, '_
> {
15 fn session(&self) -> &Session
{
19 fn code(&self) -> DiagnosticId
{
20 rustc_errors
::error_code
!(E0617
)
23 fn diagnostic_common(&self) -> DiagnosticBuilder
<'tcx
, ErrorGuaranteed
> {
24 let mut err
= self.sess
.struct_span_err_with_code(
26 &format
!("can't pass `{}` to variadic function", self.ty
),
30 if self.ty
.references_error() {
31 err
.downgrade_to_delayed_bug();
34 if let Ok(snippet
) = self.sess
.source_map().span_to_snippet(self.span
) {
37 &format
!("cast the value to `{}`", self.cast_ty
),
38 format
!("{} as {}", snippet
, self.cast_ty
),
39 Applicability
::MachineApplicable
,
42 err
.help(&format
!("cast the value to `{}`", self.cast_ty
));
48 fn diagnostic_extended(
50 mut err
: DiagnosticBuilder
<'tcx
, ErrorGuaranteed
>,
51 ) -> DiagnosticBuilder
<'tcx
, ErrorGuaranteed
> {
53 "certain types, like `{}`, must be casted before passing them to a \
54 variadic function, because of arcane ABI rules dictated by the C \