Skip to content

Commit 9e7918f

Browse files
committed
Remove another StructuredDiag impl
1 parent a06e9c8 commit 9e7918f

File tree

7 files changed

+38
-80
lines changed

7 files changed

+38
-80
lines changed

compiler/rustc_hir_analysis/messages.ftl

-4
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,6 @@ hir_analysis_paren_sugar_attribute = the `#[rustc_paren_sugar]` attribute is a t
373373
hir_analysis_parenthesized_fn_trait_expansion =
374374
parenthesized trait syntax expands to `{$expanded_type}`
375375
376-
hir_analysis_pass_to_variadic_function = can't pass `{$ty}` to variadic function
377-
.suggestion = cast the value to `{$cast_ty}`
378-
.help = cast the value to `{$cast_ty}`
379-
380376
hir_analysis_pattern_type_non_const_range = range patterns must have constant range start and end
381377
hir_analysis_pattern_type_wild_pat = wildcard patterns are not permitted for pattern types
382378
.label = this type is the same as the inner type without a pattern

compiler/rustc_hir_analysis/src/errors.rs

-14
Original file line numberDiff line numberDiff line change
@@ -692,20 +692,6 @@ pub(crate) struct TypeOf<'tcx> {
692692
pub ty: Ty<'tcx>,
693693
}
694694

695-
#[derive(Diagnostic)]
696-
#[diag(hir_analysis_pass_to_variadic_function, code = E0617)]
697-
pub(crate) struct PassToVariadicFunction<'tcx, 'a> {
698-
#[primary_span]
699-
pub span: Span,
700-
pub ty: Ty<'tcx>,
701-
pub cast_ty: &'a str,
702-
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
703-
pub sugg_span: Option<Span>,
704-
pub replace: String,
705-
#[help]
706-
pub help: Option<()>,
707-
}
708-
709695
#[derive(Diagnostic)]
710696
#[diag(hir_analysis_invalid_union_field, code = E0740)]
711697
pub(crate) struct InvalidUnionField {

compiler/rustc_hir_analysis/src/structured_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
mod missing_cast_for_variadic_arg;
21
mod wrong_number_of_generic_args;
32

4-
pub use self::{missing_cast_for_variadic_arg::*, wrong_number_of_generic_args::*};
3+
pub use self::wrong_number_of_generic_args::*;
54

65
use rustc_errors::{Diag, ErrCode};
76
use rustc_session::Session;

compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs

-57
This file was deleted.

compiler/rustc_hir_typeck/messages.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ hir_typeck_cast_thin_pointer_to_fat_pointer = cannot cast thin pointer `{$expr_t
3838
3939
For more information about casts, take a look at The Book:
4040
https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions",
41+
4142
hir_typeck_cast_unknown_pointer = cannot cast {$to ->
4243
[true] to
4344
*[false] from
@@ -138,6 +139,11 @@ hir_typeck_option_result_asref = use `{$def_path}::as_ref` to convert `{$expecte
138139
hir_typeck_option_result_cloned = use `{$def_path}::cloned` to clone the value inside the `{$def_path}`
139140
hir_typeck_option_result_copied = use `{$def_path}::copied` to copy the value inside the `{$def_path}`
140141
142+
hir_typeck_pass_to_variadic_function = can't pass `{$ty}` to variadic function
143+
.suggestion = cast the value to `{$cast_ty}`
144+
.help = cast the value to `{$cast_ty}`
145+
.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
146+
141147
hir_typeck_ptr_cast_add_auto_to_object = adding {$traits_len ->
142148
[1] an auto trait {$traits}
143149
*[other] auto traits {$traits}

compiler/rustc_hir_typeck/src/errors.rs

+16
Original file line numberDiff line numberDiff line change
@@ -708,3 +708,19 @@ pub(crate) struct CastThinPointerToFatPointer<'tcx> {
708708
#[note(hir_typeck_teach_help)]
709709
pub(crate) teach: Option<()>,
710710
}
711+
712+
#[derive(Diagnostic)]
713+
#[diag(hir_typeck_pass_to_variadic_function, code = E0617)]
714+
pub(crate) struct PassToVariadicFunction<'tcx, 'a> {
715+
#[primary_span]
716+
pub span: Span,
717+
pub ty: Ty<'tcx>,
718+
pub cast_ty: &'a str,
719+
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
720+
pub sugg_span: Option<Span>,
721+
pub replace: String,
722+
#[help]
723+
pub help: Option<()>,
724+
#[note(hir_typeck_teach_help)]
725+
pub(crate) teach: Option<()>,
726+
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use rustc_hir::{ExprKind, HirId, Node, QPath};
2828
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
2929
use rustc_hir_analysis::check::potentially_plural_count;
3030
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
31-
use rustc_hir_analysis::structured_errors::StructuredDiag;
3231
use rustc_index::IndexVec;
3332
use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt};
3433
use rustc_infer::infer::TypeTrace;
@@ -406,9 +405,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
406405
ty: Ty<'tcx>,
407406
cast_ty: &str,
408407
) {
409-
use rustc_hir_analysis::structured_errors::MissingCastForVariadicArg;
408+
let (sugg_span, replace, help) =
409+
if let Ok(snippet) = sess.source_map().span_to_snippet(span) {
410+
(Some(span), format!("{snippet} as {cast_ty}"), None)
411+
} else {
412+
(None, "".to_string(), Some(()))
413+
};
410414

411-
MissingCastForVariadicArg { sess, span, ty, cast_ty }.diagnostic().emit();
415+
sess.dcx().emit_err(errors::PassToVariadicFunction {
416+
span,
417+
ty,
418+
cast_ty,
419+
help,
420+
replace,
421+
sugg_span,
422+
teach: sess.teach(E0617).then_some(()),
423+
});
412424
}
413425

414426
// There are a few types which get autopromoted when passed via varargs

0 commit comments

Comments
 (0)