mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Remove another StructuredDiag
impl
This commit is contained in:
parent
a06e9c83f6
commit
9e7918f70e
@ -373,10 +373,6 @@ hir_analysis_paren_sugar_attribute = the `#[rustc_paren_sugar]` attribute is a t
|
||||
hir_analysis_parenthesized_fn_trait_expansion =
|
||||
parenthesized trait syntax expands to `{$expanded_type}`
|
||||
|
||||
hir_analysis_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}`
|
||||
|
||||
hir_analysis_pattern_type_non_const_range = range patterns must have constant range start and end
|
||||
hir_analysis_pattern_type_wild_pat = wildcard patterns are not permitted for pattern types
|
||||
.label = this type is the same as the inner type without a pattern
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ hir_typeck_cast_thin_pointer_to_fat_pointer = cannot cast thin pointer `{$expr_t
|
||||
|
||||
For more information about casts, take a look at The Book:
|
||||
https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions",
|
||||
|
||||
hir_typeck_cast_unknown_pointer = cannot cast {$to ->
|
||||
[true] to
|
||||
*[false] from
|
||||
@ -138,6 +139,11 @@ hir_typeck_option_result_asref = use `{$def_path}::as_ref` to convert `{$expecte
|
||||
hir_typeck_option_result_cloned = use `{$def_path}::cloned` to clone the value inside the `{$def_path}`
|
||||
hir_typeck_option_result_copied = use `{$def_path}::copied` to copy the value inside the `{$def_path}`
|
||||
|
||||
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 ->
|
||||
[1] an auto trait {$traits}
|
||||
*[other] auto traits {$traits}
|
||||
|
@ -708,3 +708,19 @@ pub(crate) struct CastThinPointerToFatPointer<'tcx> {
|
||||
#[note(hir_typeck_teach_help)]
|
||||
pub(crate) teach: Option<()>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_typeck_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<()>,
|
||||
#[note(hir_typeck_teach_help)]
|
||||
pub(crate) teach: Option<()>,
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ use rustc_hir::{ExprKind, HirId, Node, QPath};
|
||||
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
|
||||
use rustc_hir_analysis::check::potentially_plural_count;
|
||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
||||
use rustc_hir_analysis::structured_errors::StructuredDiag;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt};
|
||||
use rustc_infer::infer::TypeTrace;
|
||||
@ -406,9 +405,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
ty: Ty<'tcx>,
|
||||
cast_ty: &str,
|
||||
) {
|
||||
use rustc_hir_analysis::structured_errors::MissingCastForVariadicArg;
|
||||
let (sugg_span, replace, help) =
|
||||
if let Ok(snippet) = sess.source_map().span_to_snippet(span) {
|
||||
(Some(span), format!("{snippet} as {cast_ty}"), None)
|
||||
} else {
|
||||
(None, "".to_string(), Some(()))
|
||||
};
|
||||
|
||||
MissingCastForVariadicArg { sess, span, ty, cast_ty }.diagnostic().emit();
|
||||
sess.dcx().emit_err(errors::PassToVariadicFunction {
|
||||
span,
|
||||
ty,
|
||||
cast_ty,
|
||||
help,
|
||||
replace,
|
||||
sugg_span,
|
||||
teach: sess.teach(E0617).then_some(()),
|
||||
});
|
||||
}
|
||||
|
||||
// There are a few types which get autopromoted when passed via varargs
|
||||
|
Loading…
Reference in New Issue
Block a user