1
Fork 0

Remove another StructuredDiag impl

This commit is contained in:
Oli Scherer 2024-07-05 08:14:40 +00:00
parent a06e9c83f6
commit 9e7918f70e
7 changed files with 38 additions and 80 deletions

View file

@ -692,20 +692,6 @@ pub(crate) struct TypeOf<'tcx> {
pub ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_pass_to_variadic_function, code = E0617)]
pub(crate) struct PassToVariadicFunction<'tcx, 'a> {
#[primary_span]
pub span: Span,
pub ty: Ty<'tcx>,
pub cast_ty: &'a str,
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
pub sugg_span: Option<Span>,
pub replace: String,
#[help]
pub help: Option<()>,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_invalid_union_field, code = E0740)]
pub(crate) struct InvalidUnionField {

View file

@ -1,7 +1,6 @@
mod missing_cast_for_variadic_arg;
mod wrong_number_of_generic_args;
pub use self::{missing_cast_for_variadic_arg::*, wrong_number_of_generic_args::*};
pub use self::wrong_number_of_generic_args::*;
use rustc_errors::{Diag, ErrCode};
use rustc_session::Session;

View file

@ -1,57 +0,0 @@
use crate::{errors, structured_errors::StructuredDiag};
use rustc_errors::{codes::*, Diag};
use rustc_middle::ty::{Ty, TypeVisitableExt};
use rustc_session::Session;
use rustc_span::Span;
pub struct MissingCastForVariadicArg<'tcx, 's> {
pub sess: &'tcx Session,
pub span: Span,
pub ty: Ty<'tcx>,
pub cast_ty: &'s str,
}
impl<'tcx> StructuredDiag<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
fn session(&self) -> &Session {
self.sess
}
fn code(&self) -> ErrCode {
E0617
}
fn diagnostic_common(&self) -> Diag<'tcx> {
let (sugg_span, replace, help) =
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
(Some(self.span), format!("{} as {}", snippet, self.cast_ty), None)
} else {
(None, "".to_string(), Some(()))
};
let mut err = self.sess.dcx().create_err(errors::PassToVariadicFunction {
span: self.span,
ty: self.ty,
cast_ty: self.cast_ty,
help,
replace,
sugg_span,
});
if self.ty.references_error() {
err.downgrade_to_delayed_bug();
}
err
}
fn diagnostic_extended(&self, mut err: Diag<'tcx>) -> Diag<'tcx> {
err.note(format!(
"certain types, like `{}`, must be casted before passing them to a \
variadic function, because of arcane ABI rules dictated by the C \
standard",
self.ty
));
err
}
}