about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/structured_errors
diff options
context:
space:
mode:
authorObei Sideg <obei.sideg@gmail.com>2023-02-25 20:26:48 +0300
committerObei Sideg <obei.sideg@gmail.com>2023-03-05 00:01:55 +0300
commit44eb974b235df8d5d5fa7daea1203f80918a9de7 (patch)
tree606b2bc22197fb1b7b987e48ad59a5426228b68d /compiler/rustc_hir_analysis/src/structured_errors
parentb1719530f44e3c8ec903f76020a52bd8764d5d10 (diff)
downloadrust-44eb974b235df8d5d5fa7daea1203f80918a9de7.tar.gz
rust-44eb974b235df8d5d5fa7daea1203f80918a9de7.zip
migrate `rustc_hir_analysis` to session diagnostic
part two
files list:
rustc_hir_analysis/variance/*
rustc_hir_analysis/missing_cast_for_variadic_arg.rs
rustc_hir_analysis/sized_unsized_cast.rs
Diffstat (limited to 'compiler/rustc_hir_analysis/src/structured_errors')
-rw-r--r--compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs35
-rw-r--r--compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs15
2 files changed, 23 insertions, 27 deletions
diff --git a/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs b/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs
index 089491bef5e..0bfbf99cb0b 100644
--- a/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs
+++ b/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs
@@ -1,5 +1,5 @@
-use crate::structured_errors::StructuredDiagnostic;
-use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId, ErrorGuaranteed};
+use crate::{errors, structured_errors::StructuredDiagnostic};
+use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorGuaranteed};
 use rustc_middle::ty::{Ty, TypeVisitableExt};
 use rustc_session::Session;
 use rustc_span::Span;
@@ -21,27 +21,26 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
     }
 
     fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
-        let mut err = self.sess.struct_span_err_with_code(
-            self.span,
-            &format!("can't pass `{}` to variadic function", self.ty),
-            self.code(),
-        );
+        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.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();
         }
 
-        if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
-            err.span_suggestion(
-                self.span,
-                &format!("cast the value to `{}`", self.cast_ty),
-                format!("{} as {}", snippet, self.cast_ty),
-                Applicability::MachineApplicable,
-            );
-        } else {
-            err.help(&format!("cast the value to `{}`", self.cast_ty));
-        }
-
         err
     }
 
diff --git a/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs b/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs
index 3b9fb367813..910417abe6e 100644
--- a/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs
+++ b/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs
@@ -1,4 +1,4 @@
-use crate::structured_errors::StructuredDiagnostic;
+use crate::{errors, structured_errors::StructuredDiagnostic};
 use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorGuaranteed};
 use rustc_middle::ty::{Ty, TypeVisitableExt};
 use rustc_session::Session;
@@ -21,14 +21,11 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> {
     }
 
     fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
-        let mut err = self.sess.struct_span_err_with_code(
-            self.span,
-            &format!(
-                "cannot cast thin pointer `{}` to fat pointer `{}`",
-                self.expr_ty, self.cast_ty
-            ),
-            self.code(),
-        );
+        let mut err = self.sess.create_err(errors::CastThinPointerToFatPointer {
+            span: self.span,
+            expr_ty: self.expr_ty,
+            cast_ty: self.cast_ty.to_owned(),
+        });
 
         if self.expr_ty.references_error() {
             err.downgrade_to_delayed_bug();