Remove a use of StructuredDiag
, which is incompatible with automatic error tainting and error translations
This commit is contained in:
parent
486bc278ab
commit
0d54fe0d02
9 changed files with 43 additions and 78 deletions
|
@ -55,8 +55,6 @@ hir_analysis_cannot_capture_late_bound_ty =
|
|||
cannot capture late-bound type parameter in {$what}
|
||||
.label = parameter defined here
|
||||
|
||||
hir_analysis_cast_thin_pointer_to_fat_pointer = cannot cast thin pointer `{$expr_ty}` to fat pointer `{$cast_ty}`
|
||||
|
||||
hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are forbidden when `for<...>` is present
|
||||
.label = `for<...>` is here
|
||||
|
||||
|
|
|
@ -707,15 +707,6 @@ pub(crate) struct PassToVariadicFunction<'tcx, 'a> {
|
|||
pub help: Option<()>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_cast_thin_pointer_to_fat_pointer, code = E0607)]
|
||||
pub(crate) struct CastThinPointerToFatPointer<'tcx> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub expr_ty: Ty<'tcx>,
|
||||
pub cast_ty: String,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_invalid_union_field, code = E0740)]
|
||||
pub(crate) struct InvalidUnionField {
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
mod missing_cast_for_variadic_arg;
|
||||
mod sized_unsized_cast;
|
||||
mod wrong_number_of_generic_args;
|
||||
|
||||
pub use self::{
|
||||
missing_cast_for_variadic_arg::*, sized_unsized_cast::*, wrong_number_of_generic_args::*,
|
||||
};
|
||||
pub use self::{missing_cast_for_variadic_arg::*, wrong_number_of_generic_args::*};
|
||||
|
||||
use rustc_errors::{Diag, ErrCode};
|
||||
use rustc_session::Session;
|
||||
|
|
|
@ -1,56 +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 SizedUnsizedCast<'tcx> {
|
||||
pub sess: &'tcx Session,
|
||||
pub span: Span,
|
||||
pub expr_ty: Ty<'tcx>,
|
||||
pub cast_ty: String,
|
||||
}
|
||||
|
||||
impl<'tcx> StructuredDiag<'tcx> for SizedUnsizedCast<'tcx> {
|
||||
fn session(&self) -> &Session {
|
||||
self.sess
|
||||
}
|
||||
|
||||
fn code(&self) -> ErrCode {
|
||||
E0607
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> Diag<'tcx> {
|
||||
let mut err = self.sess.dcx().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();
|
||||
}
|
||||
|
||||
err
|
||||
}
|
||||
|
||||
fn diagnostic_extended(&self, mut err: Diag<'tcx>) -> Diag<'tcx> {
|
||||
err.help(
|
||||
"Thin pointers are \"simple\" pointers: they are purely a reference to a
|
||||
memory address.
|
||||
|
||||
Fat pointers are pointers referencing \"Dynamically Sized Types\" (also
|
||||
called DST). DST don't have a statically known size, therefore they can
|
||||
only exist behind some kind of pointers that contain additional
|
||||
information. Slices and trait objects are DSTs. In the case of slices,
|
||||
the additional information the fat pointer holds is their size.
|
||||
|
||||
To fix this error, don't try to cast directly between thin and fat
|
||||
pointers.
|
||||
|
||||
For more information about casts, take a look at The Book:
|
||||
https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions",
|
||||
);
|
||||
err
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue