1 use crate::structured_errors::StructuredDiagnostic;
2 use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
3 use rustc_middle::ty::{Ty, TypeFoldable};
4 use rustc_session::Session;
7 pub struct MissingCastForVariadicArg<'tcx> {
8 pub sess: &'tcx Session,
11 pub cast_ty: &'tcx str,
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> {
24 let mut err = if self.ty.references_error() {
25 self.sess.diagnostic().struct_dummy()
27 self.sess.struct_span_fatal_with_code(
29 &format!("can't pass `{}` to variadic function", self.ty),
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(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
50 "certain types, like `{}`, must be casted before passing them to a \
51 variadic function, because of arcane ABI rules dictated by the C \