1
Fork 0

simplify how the hir_typeck_pass_to_variadic_function diagnostic is created

This commit is contained in:
Orion Gonzalez 2024-11-29 11:15:15 +01:00
parent 0c4f3a45b8
commit ce98bf3d79
5 changed files with 69 additions and 27 deletions

View file

@ -146,7 +146,6 @@ hir_typeck_option_result_copied = use `{$def_path}::copied` to copy the value in
hir_typeck_pass_to_variadic_function = can't pass `{$ty}` to variadic function
.suggestion = cast the value to `{$cast_ty}`
.help = cast the value to `{$cast_ty}`
.teach_help = certain types, like `{$ty}`, must be casted before passing them to a variadic function, because of arcane ABI rules dictated by the C standard
hir_typeck_ptr_cast_add_auto_to_object = adding {$traits_len ->

View file

@ -789,11 +789,8 @@ pub(crate) struct PassToVariadicFunction<'a, 'tcx> {
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: bool,
#[suggestion(code = " as {cast_ty}", applicability = "machine-applicable", style = "verbose")]
pub sugg_span: Span,
#[note(hir_typeck_teach_help)]
pub(crate) teach: bool,
}

View file

@ -440,20 +440,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty: Ty<'tcx>,
cast_ty: &str,
) {
let (sugg_span, replace, help) =
if let Ok(snippet) = sess.source_map().span_to_snippet(span) {
(Some(span), format!("{snippet} as {cast_ty}"), false)
} else {
(None, "".to_string(), true)
};
sess.dcx().emit_err(errors::PassToVariadicFunction {
span,
ty,
cast_ty,
help,
replace,
sugg_span,
sugg_span: span.shrink_to_hi(),
teach: sess.teach(E0617),
});
}